diff options
author | duponin <duponin@locahlo.st> | 2022-12-11 22:54:47 +0100 |
---|---|---|
committer | duponin <duponin@locahlo.st> | 2022-12-11 22:54:47 +0100 |
commit | 452595baeda8327b862d03e450ac004679efe86e (patch) | |
tree | 4291fd61bbdbe96c3501d888995b1c4164237d0f /lib | |
parent | 204fd6faae8c39706a5ded42c7cc4fbc71a733bc (diff) | |
download | pleroma-452595baeda8327b862d03e450ac004679efe86e.tar.gz pleroma-452595baeda8327b862d03e450ac004679efe86e.zip |
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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/user.ex | 8 | ||||
-rw-r--r-- | lib/pleroma/web/api_spec/operations/account_operation.ex | 3 | ||||
-rw-r--r-- | lib/pleroma/web/mastodon_api/controllers/account_controller.ex | 6 |
3 files changed, 14 insertions, 3 deletions
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index b422e5c1d..17f6b9a0d 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -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 diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex index 012cbdc79..aabe988f7 100644 --- a/lib/pleroma/web/api_spec/operations/account_operation.ex +++ b/lib/pleroma/web/api_spec/operations/account_operation.ex @@ -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 diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index 7c24c35d2..656a861cd 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -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 |