mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-06 11:23:48 -05:00
Treat 400s from the api as internal server errors
if we expect a 400 (for example, the api returns 400 if the service name is already in use) then we should handle that from the view function so we can correctly display a relevation error message to the user. But if it returns a 400 that we didn't expect (for example, because we sent variables of the wrong type through to an endpoint with a schema), then that is a bug that we should fix as any other raised exception. By treating it as a 500 we encourage users to report it to us, and also will get an alert email
This commit is contained in:
@@ -614,15 +614,10 @@ def register_errorhandlers(application): # noqa (C901 too complex)
|
||||
error.message
|
||||
))
|
||||
error_code = error.status_code
|
||||
if error_code == 400:
|
||||
if isinstance(error.message, str):
|
||||
msg = [error.message]
|
||||
else:
|
||||
msg = list(itertools.chain(*[error.message[x] for x in error.message.keys()]))
|
||||
resp = make_response(render_template("error/400.html", message=msg))
|
||||
return useful_headers_after_request(resp)
|
||||
elif error_code not in [401, 404, 403, 410]:
|
||||
# probably a 500 or 503
|
||||
if error_code not in [401, 404, 403, 410]:
|
||||
# probably a 500 or 503.
|
||||
# it might be a 400, which we should handle as if it's an internal server error. If the API might
|
||||
# legitimately return a 400, we should handle that within the view or the client that calls it.
|
||||
application.logger.exception("API {} failed with status {} message {}".format(
|
||||
error.response.url if error.response else 'unknown',
|
||||
error.status_code,
|
||||
|
||||
Reference in New Issue
Block a user