Skip to content

Commit

Permalink
Fix HTTP Status Code returned for a Failed Precondition error
Browse files Browse the repository at this point in the history
Fixes grpc-ecosystem#972 (and reverses grpc-ecosystem#657). This now returns the semantically correct `400` response, rather than a `412`. This matches the gRPC documentation.
  • Loading branch information
cjcormack authored and johanbrandhorst committed Jul 22, 2019
1 parent c234fc3 commit eaf17ae
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion runtime/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func HTTPStatusFromCode(code codes.Code) int {
case codes.ResourceExhausted:
return http.StatusTooManyRequests
case codes.FailedPrecondition:
return http.StatusPreconditionFailed
// Note, this deliberately doesn't translate to the similarly named '412 Precondition Failed' HTTP response status.
return http.StatusBadRequest
case codes.Aborted:
return http.StatusConflict
case codes.OutOfRange:
Expand Down
2 changes: 1 addition & 1 deletion runtime/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestDefaultHTTPError(t *testing.T) {
},
{
err: statusWithDetails.Err(),
status: http.StatusPreconditionFailed,
status: http.StatusBadRequest,
msg: "failed precondition",
details: "type.googleapis.com/google.rpc.PreconditionFailure",
},
Expand Down

0 comments on commit eaf17ae

Please sign in to comment.