mirror of
https://github.com/mgerb/classic-wow-forums
synced 2026-01-10 09:02:50 +00:00
init
This commit is contained in:
22
lib/myapp_web/response.ex
Normal file
22
lib/myapp_web/response.ex
Normal file
@@ -0,0 +1,22 @@
|
||||
defmodule MyAppWeb.Response do
|
||||
|
||||
# error handling based on http status
|
||||
def json(conn, data) do
|
||||
|
||||
output = cond do
|
||||
conn.status && conn.status >= 400 ->
|
||||
%{
|
||||
error: %{
|
||||
status: conn.status,
|
||||
message: data,
|
||||
}
|
||||
}
|
||||
|
||||
true -> %{
|
||||
data: data
|
||||
}
|
||||
end
|
||||
|
||||
Phoenix.Controller.json(conn, output)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user