Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert any ChaliceViewError to a response #1886

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions chalice/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ def __init__(self, connection_id):
class ChaliceViewError(ChaliceError):
STATUS_CODE = 500

def to_response(self):
return Response(
body={
'Code': self.__class__.__name__,
'Message': str(self)},
status_code=self.STATUS_CODE
)


class ChaliceUnhandledError(ChaliceError):
"""This error is not caught from a Chalice view function.
Expand Down Expand Up @@ -1760,9 +1768,7 @@ def _get_view_function_response(self, view_function, function_args):
except ChaliceViewError as e:
# Any chalice view error should propagate. These
# get mapped to various HTTP status codes in API Gateway.
response = Response(body={'Code': e.__class__.__name__,
'Message': str(e)},
status_code=e.STATUS_CODE)
response = e.to_response()
except Exception:
response = self._unhandled_exception_to_response()
return response
Expand Down