Change 501 errors to 405 (#80)

* Unimplemented errors should result in a 405 instead of a 501.
pull/77/head
Todd Knight 6 years ago committed by GitHub
parent 44152ae63e
commit 6dd083fa42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -41,7 +41,7 @@ func TestHandleGrpcGateway(t *testing.T) {
{
"Unimplemented path",
"v1/orgs/1/projects/2/host-catalogs/3/host-sets/4",
http.StatusNotImplemented,
http.StatusMethodNotAllowed,
},
}
for _, tc := range cases {

@ -35,6 +35,10 @@ func InvalidArgumentErrorf(msg string, fields []string) error {
func statusErrorToApiError(s *status.Status) *pb.Error {
apiErr := &pb.Error{}
apiErr.Status = int32(runtime.HTTPStatusFromCode(s.Code()))
if s.Code() == codes.Unimplemented {
// Instead of returning a 501 we always want to return a 405 when a method isn't implemented.
apiErr.Status = http.StatusMethodNotAllowed
}
apiErr.Message = s.Message()
// TODO(ICU-193): Decouple from the status codes and instead use codes defined specifically for our API.
apiErr.Code = s.Code().String()

Loading…
Cancel
Save