Skip to content
This repository was archived by the owner on Feb 4, 2021. It is now read-only.

Commit 0a4746f

Browse files
authored
Merge pull request #49 from gedorinku/recover
recover
2 parents 0980d3b + a6df95d commit 0a4746f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

app/interceptor/recover.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package interceptor
2+
3+
import (
4+
"context"
5+
6+
"google.golang.org/grpc"
7+
"google.golang.org/grpc/grpclog"
8+
9+
"github.com/ProgrammingLab/prolab-accounts/app/util"
10+
)
11+
12+
// RecoverUnaryServerInterceptor returns the recover interceptor
13+
func RecoverUnaryServerInterceptor() grpc.UnaryServerInterceptor {
14+
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
15+
defer func() {
16+
if e := util.ErrorFromRecover(recover()); e != nil {
17+
err = errInternalServer
18+
grpclog.Errorf("recover: %+v", e)
19+
}
20+
}()
21+
return handler(ctx, req)
22+
}
23+
}

app/run.go

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func Run() error {
4646
runtime.WithMarshalerOption(runtime.MIMEWildcard, &runtime.JSONPb{OrigName: true, EmitDefaults: true}),
4747
),
4848
grapiserver.WithGrpcServerUnaryInterceptors(
49+
interceptor.RecoverUnaryServerInterceptor(),
4950
interceptor.ErrorUnaryServerInterceptor(),
5051
interceptor.ValidationUnaryServerInterceptor(),
5152
authorizator.UnaryServerInterceptor(),

0 commit comments

Comments
 (0)