Uploading avatar exceeding avatar limits should return 4xx errors instead of 500
Environment
- Installation type (OTP or From Source): OTP
- Pleroma version (could be found in the "Version" tab of settings in Pleroma-FE): https://lily.kazv.moe/infra/pleroma/commit/c8b26d7e2
- Elixir version (
elixir -v
for from source installations, N/A for OTP): N/A - Operating system: Docker, on Ubuntu 20.04
- PostgreSQL version (
psql -V
): 13.5
Bug description
0: Upload an avatar via PATCH /api/v1/accounts/update_credentials exceeding the size limit of avatars
1: Returns 500
Corresponding logs:
| 13:58:03.058 [info] PATCH /api/v1/accounts/update_credentials
|
| 13:58:03.151 [info] GET /api/v1/pleroma/chats
|
| 13:58:03.160 request_id=Ft4bcGHA8oXWhwMC8tHj [info] Sent 200 in 9ms
|
| 13:58:03.199 request_id=Ft4bcFw0_qzTCHkF7z1i [error] Elixir.Pleroma.Upload store (using Pleroma.Uploaders.Local) failed: :file_too_large
|
| 13:58:03.215 request_id=Ft4bcFw0_qzTCHkF7z1i [error] Internal server error: %Protocol.UndefinedError{description: "Jason.Encoder protocol must always be explicitly implemented.\n\nIf you own the struct, you can derive the implementation specifying which fields should be encoded to JSON:\n\n @derive {Jason.Encoder, only: [....]}\n defstruct ...\n\nIt is also possible to encode all fields, although this should be used carefully to avoid accidentally leaking private information when new fields are added:\n\n @derive Jason.Encoder\n defstruct ...\n\nFinally, if you don't own the struct you want to encode to JSON, you may use Protocol.derive/3 placed outside of any module:\n\n Protocol.derive(Jason.Encoder, NameOfTheStruct, only: [...])\n Protocol.derive(Jason.Encoder, NameOfTheStruct)\n", protocol: Jason.Encoder, value: %Plug.Upload{content_type: "image/png", filename: "0c05792c028a7e3198316cdb080bafba43df9fa4851db0c6f62c16028f8bc2c8.png", path: "/tmp/plug-1647/multipart-1647784683-370656199897468-2"}}
|
| 13:58:03.215 request_id=Ft4bcFw0_qzTCHkF7z1i [info] Sent 500 in 157ms
The backend should instead send a 4xx error indicating the request was too large, as it is not the server's fault.