Skip to content

Use exceptions to return error responses #34

@JamieCressey

Description

@JamieCressey

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions