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

Add error handlers for api routes #11722

Open
jacobtylerwalls opened this issue Jan 9, 2025 · 0 comments
Open

Add error handlers for api routes #11722

jacobtylerwalls opened this issue Jan 9, 2025 · 0 comments

Comments

@jacobtylerwalls
Copy link
Member

jacobtylerwalls commented Jan 9, 2025

Problem
The routes in core arches serve a mixture of HTML and JSON. We've generally been using the api/ prefix to clarify which ones should return JSON. Without further configuration, a view or decorator raising an error will return Django's default HTML error responses, which can confuse a client expecting to always parse JSON, as shown below.

Recently written API views have been trying to catch and transform errors to JSON, but this is both verbose and not bullet-proof, e.g. see @group_required decorator below.

Suggest to add custom 400, 403, 404 (maybe) and 500 handlers that sniff for whether it's an api route (prefixed with api/ or api., I guess?) and return JSON instead.

Log in to lingo as tester3/Test12345!
See:

html-no-parse

This is because the @group_required decorator on ConceptTreeView (and the others) returns HTML, and we crash on calling .parse()

Originally posted by @jacobtylerwalls in archesproject/arches-lingo#86 (comment)


An alternative to inspecting the route prefix would be to segregate the routes into two python modules and switch on that. We could look into how backward compatible this would be.

@chiatt chiatt added this to pipeline Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant