File tree 5 files changed +17
-1
lines changed
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.
24
24
Type codes are strings that are returned by any error that implements ` errors.TypeCoder ` .
25
25
26
26
type TypeCoder interface {
27
+ error
27
28
TypeCode() string
28
29
}
29
30
@@ -33,15 +34,17 @@ HTTP statuses are integer values that have defined in the `net/http` package and
33
34
implements ` errors.HTTPCoder ` .
34
35
35
36
type HTTPCoder interface {
37
+ error
36
38
HTTPCode() int
37
39
}
38
40
39
- ### GRCP Codes
41
+ ### GRPC Codes
40
42
41
43
GRPC codes are ` codes.Code ` are int64 values defined in the ` google.golang.org/grpc/codes ` package and are returned by
42
44
any error that implements ` errors.GRPCCoder ` .
43
45
44
46
type GRPCCoder interface {
47
+ error
45
48
GRPCCode() codes.Code
46
49
}
47
50
Original file line number Diff line number Diff line change 7
7
8
8
// TypeCoder interface to extract an errors embeddable type as a string
9
9
type TypeCoder interface {
10
+ error
10
11
TypeCode () string
11
12
}
12
13
Original file line number Diff line number Diff line change 8
8
)
9
9
10
10
type GRPCCoder interface {
11
+ error
11
12
GRPCCode () codes.Code
12
13
}
13
14
@@ -62,6 +63,10 @@ func (e Error) GRPCCode() codes.Code {
62
63
return codes .DeadlineExceeded
63
64
case ErrConflict :
64
65
return codes .AlreadyExists
66
+ case ErrGone :
67
+ return codes .NotFound
68
+ case ErrUnsupportedMediaType :
69
+ return codes .InvalidArgument
65
70
case ErrImATeapot :
66
71
return codes .Unknown
67
72
case ErrUnprocessableEntity :
Original file line number Diff line number Diff line change 6
6
)
7
7
8
8
type HTTPCoder interface {
9
+ error
9
10
HTTPCode () int
10
11
}
11
12
@@ -60,6 +61,10 @@ func (e Error) HTTPCode() int {
60
61
return http .StatusRequestTimeout
61
62
case ErrConflict :
62
63
return http .StatusConflict
64
+ case ErrGone :
65
+ return http .StatusGone
66
+ case ErrUnsupportedMediaType :
67
+ return http .StatusUnsupportedMediaType
63
68
case ErrImATeapot :
64
69
return 418 // teapot support
65
70
case ErrUnprocessableEntity :
Original file line number Diff line number Diff line change @@ -29,6 +29,8 @@ const (
29
29
ErrMethodNotAllowed Error = "METHOD_NOT_ALLOWED" // HTTP: 405 GRPC: codes.Unimplemented
30
30
ErrRequestTimeout Error = "REQUEST_TIMEOUT" // HTTP: 408 GRPC: codes.DeadlineExceeded
31
31
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
32
34
ErrImATeapot Error = "IM_A_TEAPOT" // HTTP: 418 GRPC: codes.Unknown
33
35
ErrUnprocessableEntity Error = "UNPROCESSABLE_ENTITY" // HTTP: 422 GRPC: codes.InvalidArgument
34
36
ErrTooManyRequests Error = "TOO_MANY_REQUESTS" // HTTP: 429 GRPC: codes.ResourceExhausted
You can’t perform that action at this time.
0 commit comments