2019-08-26 06:16:40 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-08-26 06:16:40 -06:00
|
|
|
# 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
|
|
|
|
|
2020-05-18 00:51:53 -06:00
|
|
|
def call(conn, {:error, :forbidden}) do
|
|
|
|
render_error(conn, :forbidden, "Access denied")
|
|
|
|
end
|
|
|
|
|
2019-08-26 06:16:40 -06:00
|
|
|
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
|