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

Use exceptions to return error responses #34

Closed
JamieCressey opened this issue Jul 12, 2016 · 2 comments
Closed

Use exceptions to return error responses #34

JamieCressey opened this issue Jul 12, 2016 · 2 comments

Comments

@JamieCressey
Copy link

JamieCressey commented Jul 12, 2016

I've not delved too deep into this yet, so I'm not sure how straight forward this would be to implement...

Having the ability to use exceptions to return an error response (and correct HTTP response code) would be extremely useful. A pseudo example:

Exception class:

class UnauthorizedException(ChaliceError):
    STATUS_CODE = 401

App logic:

if not authenticate(user):
    raise UnauthorizedException('You are not authenticated')

Response example (inc. correct response headers):

{"error": e.message}

Having quickly checked the source code, it looks like it should just be a cause of creating the exceptions and adding them to the ALL_ERRORS list.

Thoughts?

@jamesls
Copy link
Member

jamesls commented Jul 12, 2016

I think that's a great idea.

@jamesls
Copy link
Member

jamesls commented Aug 1, 2016

Closing, implemented in #37

@jamesls jamesls closed this as completed Aug 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants