Uploading an avatar media exceeding max size returns a 413
Until now it was returning a 500 because the upload plug were going through the changeset and ending in the JSON encoder, which raised because struct has to @derive the encoder.
This commit is contained in:
parent
204fd6faae
commit
452595baed
4 changed files with 42 additions and 3 deletions
|
|
@ -611,7 +611,13 @@ defmodule Pleroma.User do
|
|||
{:ok, new_value} <- value_function.(value) do
|
||||
put_change(changeset, map_field, new_value)
|
||||
else
|
||||
_ -> changeset
|
||||
{:error, :file_too_large} ->
|
||||
Ecto.Changeset.validate_change(changeset, map_field, fn map_field, _value ->
|
||||
[{map_field, "file is too large"}]
|
||||
end)
|
||||
|
||||
_ ->
|
||||
changeset
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,8 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
|
|||
requestBody: request_body("Parameters", update_credentials_request(), required: true),
|
||||
responses: %{
|
||||
200 => Operation.response("Account", "application/json", Account),
|
||||
403 => Operation.response("Error", "application/json", ApiError)
|
||||
403 => Operation.response("Error", "application/json", ApiError),
|
||||
413 => Operation.response("Error", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -254,7 +254,11 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
|
|||
with_pleroma_settings: true
|
||||
)
|
||||
else
|
||||
_e -> render_error(conn, :forbidden, "Invalid request")
|
||||
{:error, %Ecto.Changeset{errors: [avatar: {"file is too large", _}]}} ->
|
||||
render_error(conn, :request_entity_too_large, "File is too large")
|
||||
|
||||
_e ->
|
||||
render_error(conn, :forbidden, "Invalid request")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue