1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.FallbackController do
6 use Pleroma.Web, :controller
8 def call(conn, {:error, %Ecto.Changeset{} = changeset}) do
11 |> Ecto.Changeset.traverse_errors(fn {message, _opt} -> message end)
12 |> Enum.map_join(", ", fn {_k, v} -> v end)
15 |> put_status(:unprocessable_entity)
16 |> json(%{error: error_message})
19 def call(conn, {:error, :not_found}) do
20 render_error(conn, :not_found, "Record not found")
23 def call(conn, {:error, :forbidden}) do
24 render_error(conn, :forbidden, "Access denied")
27 def call(conn, {:error, error_message}) do
29 |> put_status(:bad_request)
30 |> json(%{error: error_message})
33 def call(conn, {:error, status, message}) do
36 |> json(%{error: message})
41 |> put_status(:internal_server_error)
42 |> json(dgettext("errors", "Something went wrong"))