Skip to content

Commit ff4a9c2

Browse files
committed
add Gone and UnsupportedMediaType http errors
- Fix some docs - Fix some type interfaces
1 parent 89ceac1 commit ff4a9c2

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ that can then be shared between services.
2424
Type 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
3334
implements `errors.HTTPCoder`.
3435

3536
type HTTPCoder interface {
37+
error
3638
HTTPCode() int
3739
}
3840

39-
### GRCP Codes
41+
### GRPC Codes
4042

4143
GRPC codes are `codes.Code` are int64 values defined in the `google.golang.org/grpc/codes` package and are returned by
4244
any error that implements `errors.GRPCCoder`.
4345

4446
type GRPCCoder interface {
47+
error
4548
GRPCCode() codes.Code
4649
}
4750

errors.go

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
// TypeCoder interface to extract an errors embeddable type as a string
99
type TypeCoder interface {
10+
error
1011
TypeCode() string
1112
}
1213

grpc.go

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
)
99

1010
type 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:

http.go

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
)
77

88
type 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:

types.go

+2
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)