From bd2bfeb062ba9e1cc687abebd1e214a6d6036f35 Mon Sep 17 00:00:00 2001 From: Stan Nelson Date: Tue, 20 Mar 2018 10:08:42 -0700 Subject: [PATCH 1/3] Changed to use more appropriate http status code for ResourceExhausted. --- runtime/errors.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/errors.go b/runtime/errors.go index 429a2162400..cca5ae6e954 100644 --- a/runtime/errors.go +++ b/runtime/errors.go @@ -35,7 +35,7 @@ func HTTPStatusFromCode(code codes.Code) int { case codes.Unauthenticated: return http.StatusUnauthorized case codes.ResourceExhausted: - return http.StatusServiceUnavailable + return http.StatusRequestEntityTooLarge case codes.FailedPrecondition: return http.StatusPreconditionFailed case codes.Aborted: From e7bc1bbc959f6e8bc88aaba78a5d177eb42d8c35 Mon Sep 17 00:00:00 2001 From: Stan Nelson Date: Tue, 3 Apr 2018 13:42:20 -0700 Subject: [PATCH 2/3] Adjust status codes to match googleapis code.proto --- runtime/errors.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/runtime/errors.go b/runtime/errors.go index cca5ae6e954..0276585a317 100644 --- a/runtime/errors.go +++ b/runtime/errors.go @@ -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: @@ -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: @@ -35,9 +36,9 @@ func HTTPStatusFromCode(code codes.Code) int { case codes.Unauthenticated: return http.StatusUnauthorized case codes.ResourceExhausted: - return http.StatusRequestEntityTooLarge + return http.StatusTooManyRequests case codes.FailedPrecondition: - return http.StatusPreconditionFailed + return http.StatusBadRequest case codes.Aborted: return http.StatusConflict case codes.OutOfRange: From 3c98eae2836d07b9a878438617fe32ec06ec3b3e Mon Sep 17 00:00:00 2001 From: Stan Nelson Date: Tue, 3 Apr 2018 15:01:50 -0700 Subject: [PATCH 3/3] Fix test to match new status code mapping --- examples/integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/integration_test.go b/examples/integration_test.go index 1c8da8eee61..7a51868a99d 100644 --- a/examples/integration_test.go +++ b/examples/integration_test.go @@ -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) } }