lemmy icon indicating copy to clipboard operation
lemmy copied to clipboard

[Bug]: API does return plain HTML errors

Open tbe opened this issue 1 year ago • 4 comments

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

  1. Trigger an error (Overload, DB down, memory issues, ...)

Technical Details

Version

0.18.0

Lemmy Instance URL

No response

tbe avatar Jun 26 '23 20:06 tbe

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.

RocketDerp avatar Jun 27 '23 00:06 RocketDerp

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:

image

RocketDerp avatar Jun 27 '23 13:06 RocketDerp

I tried to fix this but couldnt get it working. It requires setting a default ErrorHandler.

Nutomic avatar Jun 30 '23 10:06 Nutomic

Taking a look at this.

PawanHegde avatar Jul 01 '23 10:07 PawanHegde