feat: panic recover

This commit is contained in:
Kirill 2023-06-20 02:12:27 +03:00
parent b5299c052c
commit 17b030ce1c
3 changed files with 16 additions and 5 deletions

@ -7,6 +7,10 @@ GRPC_PORT=8081
YOOMONEY_STORE_ID=storeid
YOOMONEY_SECRET_KEY=secret
IS_MOCK=true
MOCK_SERVICE_HOST=http://treasurer-mock:8080
YOOMONEY_WEBHOOKS_URL=http://treasurer-mock:8080/webhooks
YOOMONEY_PAYMENTS_URL=http://treasurer-mock:8080/payments
MONGO_HOST=mongo
MONGO_PORT=27017

@ -28,7 +28,7 @@ func main() {
}
}()
config, err := initialize.Configuration(".env.test")
config, err := initialize.Configuration("../../.env.test")
if err != nil {
logger.Fatal("failed to init config: %v", zap.Error(err))
}

@ -2,6 +2,7 @@ package app
import (
"context"
"errors"
"fmt"
"time"
@ -19,7 +20,14 @@ const (
shutdownTimeout = 5 * time.Second
)
func Run(ctx context.Context, config *models.Config, logger *zap.Logger) error {
func Run(ctx context.Context, config *models.Config, logger *zap.Logger) (appErr error) {
defer func() {
if recovered := recover(); recovered != nil {
appErr = errors.New("recovered panic on application run")
logger.Error("recovered panic on application run", zap.Any("recovered", recovered))
}
}()
mongoDB, connectionErr := mongo.Connect(ctx, &mongo.ConnectDeps{
Configuration: &config.Database,
Timeout: 10 * time.Second,
@ -56,6 +64,7 @@ func Run(ctx context.Context, config *models.Config, logger *zap.Logger) error {
Repositories: *repositories,
Clients: *clients,
ConfigurationHTTP: &config.HTTP,
Configuration: &config.Service,
})
if err != nil {
return err.Wrap("failed to initialize services")
@ -93,9 +102,7 @@ func Run(ctx context.Context, config *models.Config, logger *zap.Logger) error {
httpServer.Register(api)
grpcServer, err := server.NewGRPC(server.DepsGRPC{
Logger: logger,
})
grpcServer, err := server.NewGRPC(server.DepsGRPC{Logger: logger})
if err != nil {
return err.Wrap("failed to initialize grpc server")
}