Skip to content

Commit

Permalink
Include reason in "get stream" API endpoint's 404 JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
ku1ik committed Apr 12, 2024
1 parent 1ef3d97 commit ec8e9a8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/asciinema_web/controllers/api/live_stream_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ defmodule AsciinemaWeb.Api.LiveStreamController do
plug :authenticate

def show(conn, params) do
if stream = Streaming.get_live_stream(conn.assigns.current_user, params["id"]) do
id = params["id"]

if stream = Streaming.get_live_stream(conn.assigns.current_user, id) do
json(conn, %{
url: url(~p"/s/#{stream}"),
ws_producer_url: Routes.Extra.ws_producer_url(stream)
})
else
conn
|> put_status(404)
|> json(%{})
|> json(%{reason: not_found_reason(id)})
end
end

Expand All @@ -32,4 +34,7 @@ defmodule AsciinemaWeb.Api.LiveStreamController do
|> halt()
end
end

defp not_found_reason(nil), do: "stream not available for this account"
defp not_found_reason(id), do: "stream #{id} not found"
end

0 comments on commit ec8e9a8

Please sign in to comment.