Unexpected HTTP 500 response
floodico opened this issue · comments
Hi.
I put my plug on post request in router:
post("/upload", Project.Plugs.UploadHooks, :call)
There is a small part of plug:
## UploadHooks module
def call(conn, _) do
conn
|> get_req_header("hook-name")
|> trigger_hook(conn, conn.params)
end
## PRE-CREATE hook clauses
## This event will be triggered before an upload is created.
## At this stage, verification and authorization of upload metadata is performed.
defp trigger_hook(["pre-create"], conn, %{
"Upload" => %{"MetaData" => %{"user_id" => user_id, "filename_token" => token}}
}) do
with {:ok, _} <- validate_user_id(user_id),
{:ok, _} <- Druid.find_id_by_token(token),
%User{} <- Accounts.find_user(user_id),
{:ok, _} <- Resources.get_asset_by_token(token) do
Logger.info("""
#{inspect __MODULE__}[pre-create]:
Upload allowed for asset #{inspect token}\
""")
send_resp(conn, 204, "OK")
else
e ->
Logger.info("""
#{inspect __MODULE__}[pre-create]:
Upload not allowed - #{inspect e}
""")
send_resp(conn, 403, "Forbidden")
end
end
And this is how it works: the hook worked successfully and it looks like it will send 204 response, but after 2ms this exception was raised. The client receives 500 status response
Even if i do this then get the same:
conn
|> send_resp(204, "OK")
|> halt()
Can you please provide a small application that reproduces the error? Something we can run locally and take a further look at it. Thanks.
The problem was in 204 response body(need to be "") phoenixframework/phoenix#1131 (comment)
@josevalim Thanks for your response