feat: panic recover

This commit is contained in:
Kirill 2023-06-19 23:19:28 +00:00
parent 6f23d6a711
commit ca151d128f
2 changed files with 15 additions and 4 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

@ -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")
}