diff --git a/internal/core/application/transaction_service.go b/internal/core/application/transaction_service.go index 9359241..33b3e7b 100644 --- a/internal/core/application/transaction_service.go +++ b/internal/core/application/transaction_service.go @@ -20,7 +20,7 @@ import ( "github.com/vulpemventures/go-elements/transaction" "github.com/vulpemventures/ocean/internal/core/domain" "github.com/vulpemventures/ocean/internal/core/ports" - wallet "github.com/vulpemventures/ocean/pkg/wallet" + "github.com/vulpemventures/ocean/pkg/wallet" singlesig "github.com/vulpemventures/ocean/pkg/wallet/single-sig" ) @@ -90,7 +90,9 @@ func (ts *TransactionService) GetTransactionInfo( if err != nil { return nil, err } - tx = &res[0] + if len(res) != 0 { + tx = &res[0] + } } return (*TransactionInfo)(tx), nil } diff --git a/internal/interfaces/grpc/interceptor/interceptor.go b/internal/interfaces/grpc/interceptor/interceptor.go index 2936320..63a1973 100644 --- a/internal/interfaces/grpc/interceptor/interceptor.go +++ b/internal/interfaces/grpc/interceptor/interceptor.go @@ -10,6 +10,7 @@ func UnaryInterceptor() grpc.ServerOption { return grpc.UnaryInterceptor( middleware.ChainUnaryServer( unaryLogger, + unaryPanicRecoveryInterceptor(), ), ) } @@ -19,6 +20,7 @@ func StreamInterceptor() grpc.ServerOption { return grpc.StreamInterceptor( middleware.ChainStreamServer( streamLogger, + streamPanicRecoveryInterceptor(), ), ) } diff --git a/internal/interfaces/grpc/interceptor/panic.go b/internal/interfaces/grpc/interceptor/panic.go new file mode 100644 index 0000000..4c3e63c --- /dev/null +++ b/internal/interfaces/grpc/interceptor/panic.go @@ -0,0 +1,45 @@ +package grpc_interceptor + +import ( + "context" + "runtime/debug" + + log "github.com/sirupsen/logrus" + "google.golang.org/grpc" +) + +func unaryPanicRecoveryInterceptor() grpc.UnaryServerInterceptor { + return func( + ctx context.Context, + req interface{}, + info *grpc.UnaryServerInfo, + handler grpc.UnaryHandler, + ) (interface{}, error) { + defer func() { + if r := recover(); r != nil { + log.Errorf("panic-recovery middleware recovered from panic: %v", r) + log.Tracef("panic-recovery middleware recovered from panic: %v", string(debug.Stack())) + } + }() + + return handler(ctx, req) + } +} + +func streamPanicRecoveryInterceptor() grpc.StreamServerInterceptor { + return func( + srv interface{}, + stream grpc.ServerStream, + info *grpc.StreamServerInfo, + handler grpc.StreamHandler, + ) error { + defer func() { + if r := recover(); r != nil { + log.Errorf("panic-recovery middleware recovered from panic: %v", r) + log.Tracef("panic-recovery middleware recovered from panic: %v", string(debug.Stack())) + } + }() + + return handler(srv, stream) + } +}