aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSadposter <hannah+pleroma@coffee-and-dreams.uk>2019-04-06 16:20:06 +0100
committerSadposter <hannah+pleroma@coffee-and-dreams.uk>2019-04-06 16:20:06 +0100
commitc05fe4da0a9ad119891d2fc6cf82ea3beb59fec7 (patch)
tree1270eb95f7e2abdb517df114cf11f4eeca556d3f /lib
parentffac2593eaefeb3000a69f44566dfe5b2a574ae9 (diff)
downloadpleroma-c05fe4da0a9ad119891d2fc6cf82ea3beb59fec7.tar.gz
Document subscription endpoints, fix typos
Also adds a quick error case on the subscription endpoints to avoid 500s
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex20
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index e848895f1..a7c9c4735 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -864,22 +864,30 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
def subscribe(%{assigns: %{user: user}} = conn, %{"id" => id}) do
- with %User{} = subscription_target <- User.get_by_id(id) do
- {:ok, subscription_target} = User.subscribe(user, subscription_target)
-
+ with %User{} = subscription_target <- User.get_by_id(id),
+ {:ok, subscription_target} = User.subscribe(user, subscription_target) do
conn
|> put_view(AccountView)
|> render("relationship.json", %{user: user, target: subscription_target})
+ else
+ {:error, message} ->
+ conn
+ |> put_resp_content_type("application/json")
+ |> send_resp(403, Jason.encode!(%{"error" => message}))
end
end
def unsubscribe(%{assigns: %{user: user}} = conn, %{"id" => id}) do
- with %User{} = subscription_target <- User.get_by_id(id) do
- {:ok, subscription_target} = User.unsubscribe(user, subscription_target)
-
+ with %User{} = subscription_target <- User.get_by_id(id),
+ {:ok, subscription_target} = User.unsubscribe(user, subscription_target) do
conn
|> put_view(AccountView)
|> render("relationship.json", %{user: user, target: subscription_target})
+ else
+ {:error, message} ->
+ conn
+ |> put_resp_content_type("application/json")
+ |> send_resp(403, Jason.encode!(%{"error" => message}))
end
end