feat: convert grpc errors to http status codes (#1997)

* feat: convert grpc errors to http status codes

* chore: circuit break include unimplemented grpc error

* chore: add reference link in comments
This commit is contained in:
Kevin Wan
2022-06-11 23:07:26 +08:00
committed by GitHub
parent db9a1f3e27
commit ed1c937998
6 changed files with 197 additions and 2 deletions

View File

@@ -8,7 +8,7 @@ import (
// Acceptable checks if given error is acceptable.
func Acceptable(err error) bool {
switch status.Code(err) {
case codes.DeadlineExceeded, codes.Internal, codes.Unavailable, codes.DataLoss:
case codes.DeadlineExceeded, codes.Internal, codes.Unavailable, codes.DataLoss, codes.Unimplemented:
return false
default:
return true

View File

@@ -49,7 +49,6 @@ func UnaryTimeoutInterceptor(timeout time.Duration) grpc.UnaryServerInterceptor
return resp, err
case <-ctx.Done():
err := ctx.Err()
if err == context.Canceled {
err = status.Error(codes.Canceled, err.Error())
} else if err == context.DeadlineExceeded {