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

Controller multi errors #135

Open
Jaymon opened this issue Mar 23, 2024 · 2 comments
Open

Controller multi errors #135

Jaymon opened this issue Mar 23, 2024 · 2 comments

Comments

@Jaymon
Copy link
Owner

Jaymon commented Mar 23, 2024

Inspired by jsonapi:

When a server encounters multiple problems for a single request, the most generally applicable HTTP error code SHOULD be used in the response. For instance, 400 Bad Request might be appropriate for multiple 4xx errors or 500 Internal Server Error might be appropriate for multiple 5xx errors.

I like this, I need to cleanup the controller's multi errors and depending on what the errors are I can decide what code. So if I have mainly 4XX errors then I set the MultiCallError code to 400, if they're a bunch of ValueErrors or something like that then I set it to 500.

@Jaymon
Copy link
Owner Author

Jaymon commented Mar 26, 2024

Basically, MultiCallError should have an add method that will aggregate any CallErrors under the status code (so all 400-499) errors would be aggregated under 400. Any other errors would aggregate under 500, whichever one (400 or 500) has the most errors will be the error that gets raised, this could be done like this:

e = MultiCallError()
e.add(CallError(401))
e.add(CallError(403))
e.add(ValueError()) # would be considered a 500
e.raise() # would raise a new CallError(400) because there were 2 400 level errors

@Jaymon
Copy link
Owner Author

Jaymon commented Nov 12, 2024

#149

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant