lemmy
lemmy copied to clipboard
[Bug]: API does return plain HTML errors
Requirements
- [X] Is this a bug report? For questions or discussions use https://lemmy.ml/c/lemmy_support
- [X] Did you check to see if this issue already exists?
- [X] Is this only a single bug? Do not put multiple bugs in one issue.
- [X] Is this a backend issue? Use the lemmy-ui repo for UI / frontend issues.
Summary
Currently, if something goes wrong, the API produces non-json errors. It seems like the default error handler is used.
The error handler should instead respond with a JSON message.
Steps to Reproduce
- Trigger an error (Overload, DB down, memory issues, ...)
Technical Details
Version
0.18.0
Lemmy Instance URL
No response
Simple example, first query returns an empty comment list in JSON format. The second example returns a string "Query deserialize error: unknown variant Test
, expected one of All
, Local
, Subscribed
" that is not wrapped in JSON because "Test" is not a valid "_type" parameter:
curl "https://sh.itjust.works/api/v3/comment/list?post_id=372144&limit=300&sort=New&type_=Local"
curl "https://sh.itjust.works/api/v3/comment/list?post_id=372144&limit=300&sort=New&type_=Test"
It is also suggested that unique error code value be associated with each JSON error response so that the code path can be quickly identified.
From a user-interface side, this is what is happening, the toast messages on the bottom left of the browser window show it can't parse the non-JSON errors and doesn't actually show the full message:
I tried to fix this but couldnt get it working. It requires setting a default ErrorHandler.
Taking a look at this.