[RQLIO] Return contextual HTTP status codes
When requesting the rqlcontroller's /rqlio
endpoint (via cwclientlib/js), upon error, it returns a 500 HTTP status code, which is a generic status code related to a server-side error. The response body also contains an HTML response with the traceback which is inappropriate.
This status code is too generic and the endpoint could return a different status code depending on the context of the error.
Here are examples of different status codes that could be used and their context:
- 400 (Bad Request): syntax error
- 403 (Forbidden): permission error (
__permissions__
in schema) - 404 (Not Found): one of the entity name in the request doesn't exist
- 500 (Internal Server Error): an error occurred while processing the request (probably a server-side bug)
The use case is to filter out from logging the requests that led to an error due to user input error rather than a server-side bug that should be addressed.
The goal of this ticket is to explore the code and the feasibility for such modifications.
Proposed implementation:
- Have multiple kind of exceptions thrown in RQL processing depending on the context of the error (as described above)
- These exceptions are to be thrown out in entity hooks as well
- Catch these exceptions in rqlcontroller and return the appropriate status code (via Pyramid)
- The response body must be JSON, not HTML
- If the status code isn't 4XX, optionally include the traceback in the response body (encoded in the JSON tree).
- Modify cwclientlib/js appropriately.
Ref: