Change 501 errors to 405 (#80)

* Unimplemented errors should result in a 405 instead of a 501.
This commit is contained in:
Todd Knight authored and GitHub committed 2020-05-26 17:11:29 -07:00
1 parent 44152ae63e
commit 6dd083fa42
2 files changed
+5 -1

No files matched your search

+1 -1
View File
@@ -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()