mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-18 04:34:19 +01:00
IsInitialized > walletLoaded & panic recovery (#266)
* isInitialized update update walletInitialized to return true is walled.db exist, add walletLoaded that check if wallet property is nil * panic handler
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
// UnaryInterceptor returns the unary interceptor
|
||||
func UnaryInterceptor(svc *macaroons.Service) grpc.ServerOption {
|
||||
return grpc.UnaryInterceptor(middleware.ChainUnaryServer(
|
||||
unaryPanicRecoveryInterceptor(),
|
||||
unaryLogger,
|
||||
unaryMacaroonAuthHandler(svc),
|
||||
))
|
||||
@@ -17,6 +18,7 @@ func UnaryInterceptor(svc *macaroons.Service) grpc.ServerOption {
|
||||
// StreamInterceptor returns the stream interceptor with a logrus log
|
||||
func StreamInterceptor(svc *macaroons.Service) grpc.ServerOption {
|
||||
return grpc.StreamInterceptor(middleware.ChainStreamServer(
|
||||
streamPanicRecoveryInterceptor(),
|
||||
streamLogger,
|
||||
streamMacaroonAuthHandler(svc),
|
||||
))
|
||||
|
||||
45
server/internal/interface/grpc/interceptors/panic.go
Normal file
45
server/internal/interface/grpc/interceptors/panic.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package interceptors
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user