Skip to content

Commit

Permalink
Changed to use more appropriate http status code for ResourceExhausted (
Browse files Browse the repository at this point in the history
grpc-ecosystem#580)

* Adjust status codes to match googleapis code.proto
  • Loading branch information
eleniums authored and achew22 committed Apr 3, 2018
1 parent 652a7b7 commit cb42acb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ func TestTimeout(t *testing.T) {
}
defer resp.Body.Close()

if got, want := resp.StatusCode, http.StatusRequestTimeout; got != want {
if got, want := resp.StatusCode, http.StatusGatewayTimeout; got != want {
t.Errorf("resp.StatusCode = %d; want %d", got, want)
}
}
Expand Down
7 changes: 4 additions & 3 deletions runtime/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
)

// HTTPStatusFromCode converts a gRPC error code into the corresponding HTTP response status.
// See: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
func HTTPStatusFromCode(code codes.Code) int {
switch code {
case codes.OK:
Expand All @@ -25,7 +26,7 @@ func HTTPStatusFromCode(code codes.Code) int {
case codes.InvalidArgument:
return http.StatusBadRequest
case codes.DeadlineExceeded:
return http.StatusRequestTimeout
return http.StatusGatewayTimeout
case codes.NotFound:
return http.StatusNotFound
case codes.AlreadyExists:
Expand All @@ -35,9 +36,9 @@ func HTTPStatusFromCode(code codes.Code) int {
case codes.Unauthenticated:
return http.StatusUnauthorized
case codes.ResourceExhausted:
return http.StatusServiceUnavailable
return http.StatusTooManyRequests
case codes.FailedPrecondition:
return http.StatusPreconditionFailed
return http.StatusBadRequest
case codes.Aborted:
return http.StatusConflict
case codes.OutOfRange:
Expand Down

0 comments on commit cb42acb

Please sign in to comment.