aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEgor Kislitsyn <egor@kislitsyn.com>2019-08-26 19:16:40 +0700
committerEgor Kislitsyn <egor@kislitsyn.com>2019-08-26 19:16:40 +0700
commit4d82bc8b0b5a0b8b584b43330f902f8dc9637d3d (patch)
tree7ca121401568e255deae9a82a8b59f126ec93f6f /lib
parent3b1b631c2aedc8e359c296b11237fa4f6edd31e5 (diff)
downloadpleroma-4d82bc8b0b5a0b8b584b43330f902f8dc9637d3d.tar.gz
Extract MastodonAPI.MastodonAPIController.errors/2 to MastodonAPI.FallbackController
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/fallback_controller.ex34
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex31
-rw-r--r--lib/pleroma/web/mastodon_api/subscription_controller.ex4
3 files changed, 36 insertions, 33 deletions
diff --git a/lib/pleroma/web/mastodon_api/controllers/fallback_controller.ex b/lib/pleroma/web/mastodon_api/controllers/fallback_controller.ex
new file mode 100644
index 000000000..41243d5e7
--- /dev/null
+++ b/lib/pleroma/web/mastodon_api/controllers/fallback_controller.ex
@@ -0,0 +1,34 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.FallbackController do
+ use Pleroma.Web, :controller
+
+ def call(conn, {:error, %Ecto.Changeset{} = changeset}) do
+ error_message =
+ changeset
+ |> Ecto.Changeset.traverse_errors(fn {message, _opt} -> message end)
+ |> Enum.map_join(", ", fn {_k, v} -> v end)
+
+ conn
+ |> put_status(:unprocessable_entity)
+ |> json(%{error: error_message})
+ end
+
+ def call(conn, {:error, :not_found}) do
+ render_error(conn, :not_found, "Record not found")
+ end
+
+ def call(conn, {:error, error_message}) do
+ conn
+ |> put_status(:bad_request)
+ |> json(%{error: error_message})
+ end
+
+ def call(conn, _) do
+ conn
+ |> put_status(:internal_server_error)
+ |> json(dgettext("errors", "Something went wrong"))
+ end
+end
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index 53cf95fbb..e51b2d89c 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -83,7 +83,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
@local_mastodon_name "Mastodon-Local"
- action_fallback(:errors)
+ action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
def create_app(conn, params) do
scopes = Scopes.fetch_scopes(params, ["read"])
@@ -1587,35 +1587,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
json(conn, %{})
end
- # fallback action
- #
- def errors(conn, {:error, %Changeset{} = changeset}) do
- error_message =
- changeset
- |> Changeset.traverse_errors(fn {message, _opt} -> message end)
- |> Enum.map_join(", ", fn {_k, v} -> v end)
-
- conn
- |> put_status(:unprocessable_entity)
- |> json(%{error: error_message})
- end
-
- def errors(conn, {:error, :not_found}) do
- render_error(conn, :not_found, "Record not found")
- end
-
- def errors(conn, {:error, error_message}) do
- conn
- |> put_status(:bad_request)
- |> json(%{error: error_message})
- end
-
- def errors(conn, _) do
- conn
- |> put_status(:internal_server_error)
- |> json(dgettext("errors", "Something went wrong"))
- end
-
def suggestions(%{assigns: %{user: user}} = conn, _) do
suggestions = Config.get(:suggestions)
diff --git a/lib/pleroma/web/mastodon_api/subscription_controller.ex b/lib/pleroma/web/mastodon_api/subscription_controller.ex
index 255ee2f18..e2b17aab1 100644
--- a/lib/pleroma/web/mastodon_api/subscription_controller.ex
+++ b/lib/pleroma/web/mastodon_api/subscription_controller.ex
@@ -64,8 +64,6 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionController do
end
def errors(conn, _) do
- conn
- |> put_status(:internal_server_error)
- |> json(dgettext("errors", "Something went wrong"))
+ Pleroma.Web.MastodonAPI.FallbackController.call(conn, nil)
end
end