GoogleCloudPlatform / go-endpoints

Cloud Endpoints for Go
https://go-endpoints.appspot.com
Apache License 2.0
255 stars 56 forks source link

Returning HTTP error code 400 (BadRequest) for unknown errors is confusing #110

Open eliasnaur opened 9 years ago

eliasnaur commented 9 years ago

if newErrorResponse in errors.go does not recognize the given error, it constructs an "internal server error" error as expected, but with a HTTP status code of 400, which is not. This is both surprising and confuses debugging by making it harder to differentiate unexpected errors, like internal server errors from expected, but invalid requests.

The relevant code is commented:

    //for compatibility, Before behavior, always return 400 HTTP Status Code.
    // TODO(alex): where is 400 coming from?

So it seems that I'm not the only one confused by this behaviour

zboralski commented 8 years ago

It expects custom error message to be prefixed with the text mapped to each HTTP status code in net/http/status.go. If the prefix is missing, it reverts to 400 Bad Request. Even the predefined errors in go-endpoints suffer from this.

I'll fix it and submit a pull request as I found it annoying too.