File tree Expand file tree Collapse file tree 5 files changed +17
-1
lines changed
Expand file tree Collapse file tree 5 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ that can then be shared between services.
2424Type codes are strings that are returned by any error that implements ` errors.TypeCoder ` .
2525
2626 type TypeCoder interface {
27+ error
2728 TypeCode() string
2829 }
2930
@@ -33,15 +34,17 @@ HTTP statuses are integer values that have defined in the `net/http` package and
3334implements ` errors.HTTPCoder ` .
3435
3536 type HTTPCoder interface {
37+ error
3638 HTTPCode() int
3739 }
3840
39- ### GRCP Codes
41+ ### GRPC Codes
4042
4143GRPC codes are ` codes.Code ` are int64 values defined in the ` google.golang.org/grpc/codes ` package and are returned by
4244any error that implements ` errors.GRPCCoder ` .
4345
4446 type GRPCCoder interface {
47+ error
4548 GRPCCode() codes.Code
4649 }
4750
Original file line number Diff line number Diff line change 77
88// TypeCoder interface to extract an errors embeddable type as a string
99type TypeCoder interface {
10+ error
1011 TypeCode () string
1112}
1213
Original file line number Diff line number Diff line change 88)
99
1010type GRPCCoder interface {
11+ error
1112 GRPCCode () codes.Code
1213}
1314
@@ -62,6 +63,10 @@ func (e Error) GRPCCode() codes.Code {
6263 return codes .DeadlineExceeded
6364 case ErrConflict :
6465 return codes .AlreadyExists
66+ case ErrGone :
67+ return codes .NotFound
68+ case ErrUnsupportedMediaType :
69+ return codes .InvalidArgument
6570 case ErrImATeapot :
6671 return codes .Unknown
6772 case ErrUnprocessableEntity :
Original file line number Diff line number Diff line change 66)
77
88type HTTPCoder interface {
9+ error
910 HTTPCode () int
1011}
1112
@@ -60,6 +61,10 @@ func (e Error) HTTPCode() int {
6061 return http .StatusRequestTimeout
6162 case ErrConflict :
6263 return http .StatusConflict
64+ case ErrGone :
65+ return http .StatusGone
66+ case ErrUnsupportedMediaType :
67+ return http .StatusUnsupportedMediaType
6368 case ErrImATeapot :
6469 return 418 // teapot support
6570 case ErrUnprocessableEntity :
Original file line number Diff line number Diff line change @@ -29,6 +29,8 @@ const (
2929 ErrMethodNotAllowed Error = "METHOD_NOT_ALLOWED" // HTTP: 405 GRPC: codes.Unimplemented
3030 ErrRequestTimeout Error = "REQUEST_TIMEOUT" // HTTP: 408 GRPC: codes.DeadlineExceeded
3131 ErrConflict Error = "CONFLICT" // HTTP: 409 GRPC: codes.AlreadyExists
32+ ErrGone Error = "GONE" // HTTP: 410 GRPC: codes.NotFound
33+ ErrUnsupportedMediaType Error = "UNSUPPORTED_MEDIA_TYPE" // HTTP: 415 GRPC: codes.InvalidArgument
3234 ErrImATeapot Error = "IM_A_TEAPOT" // HTTP: 418 GRPC: codes.Unknown
3335 ErrUnprocessableEntity Error = "UNPROCESSABLE_ENTITY" // HTTP: 422 GRPC: codes.InvalidArgument
3436 ErrTooManyRequests Error = "TOO_MANY_REQUESTS" // HTTP: 429 GRPC: codes.ResourceExhausted
You can’t perform that action at this time.
0 commit comments