X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpleroma%2Fweb%2Fpleroma_api%2Fcontrollers%2Femoji_file_controller.ex;h=204e81311f7adfc88f2edf2e9611780b85fdf85d;hb=bfbe4e8dce2bef75c3b3a87884e5a39abb7a444e;hp=428c97de62cf0619594ad7f0e1b5be81f4911fde;hpb=b3d6cf90229ff3e9a5bd0028d4a6cbd3b68da9fe;p=akkoma
diff --git a/lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex b/lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex
index 428c97de6..204e81311 100644
--- a/lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex
+++ b/lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.EmojiFileController do
@@ -12,7 +12,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileController do
plug(
Pleroma.Web.Plugs.OAuthScopesPlug,
- %{scopes: ["write"], admin: true}
+ %{scopes: ["admin:write"]}
when action in [
:create,
:update,
@@ -42,7 +42,10 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileController do
|> json(%{error: "pack name, shortcode or filename cannot be empty"})
{:error, _} = error ->
- handle_error(conn, error, %{pack_name: pack_name})
+ handle_error(conn, error, %{
+ pack_name: pack_name,
+ message: "Unexpected error occurred while adding file to pack."
+ })
end
end
@@ -69,7 +72,11 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileController do
|> json(%{error: "new_shortcode or new_filename cannot be empty"})
{:error, _} = error ->
- handle_error(conn, error, %{pack_name: pack_name, code: shortcode})
+ handle_error(conn, error, %{
+ pack_name: pack_name,
+ code: shortcode,
+ message: "Unexpected error occurred while updating."
+ })
end
end
@@ -84,7 +91,11 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileController do
|> json(%{error: "pack name or shortcode cannot be empty"})
{:error, _} = error ->
- handle_error(conn, error, %{pack_name: pack_name, code: shortcode})
+ handle_error(conn, error, %{
+ pack_name: pack_name,
+ code: shortcode,
+ message: "Unexpected error occurred while deleting emoji file."
+ })
end
end
@@ -94,18 +105,24 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileController do
|> json(%{error: "Emoji \"#{emoji_code}\" does not exist"})
end
- defp handle_error(conn, {:error, :not_found}, %{pack_name: pack_name}) do
+ defp handle_error(conn, {:error, :enoent}, %{pack_name: pack_name}) do
conn
|> put_status(:not_found)
|> json(%{error: "pack \"#{pack_name}\" is not found"})
end
- defp handle_error(conn, {:error, _}, _) do
- render_error(
- conn,
- :internal_server_error,
- "Unexpected error occurred while adding file to pack."
- )
+ defp handle_error(conn, {:error, error}, opts) do
+ message =
+ [
+ Map.get(opts, :message, "Unexpected error occurred."),
+ Pleroma.Utils.posix_error_message(error)
+ ]
+ |> Enum.join(" ")
+ |> String.trim()
+
+ conn
+ |> put_status(:internal_server_error)
+ |> json(%{error: message})
end
defp get_filename(%Plug.Upload{filename: filename}), do: filename