Spaces:
Sleeping
Sleeping
Scott Hiett
commited on
Commit
·
5ce1d4c
1
Parent(s):
0f49779
Make 404 trigger a not_found error and respond in the standardised form
Browse files
lib/srh/http/base_router.ex
CHANGED
@@ -25,7 +25,7 @@ defmodule Srh.Http.BaseRouter do
|
|
25 |
end
|
26 |
|
27 |
match _ do
|
28 |
-
|
29 |
end
|
30 |
|
31 |
defp do_command_request(conn, success_lambda) do
|
@@ -104,13 +104,9 @@ defmodule Srh.Http.BaseRouter do
|
|
104 |
|> send_resp(code, create_response_body(resp_data))
|
105 |
end
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
Jason.encode!(data)
|
110 |
-
end
|
111 |
|
112 |
-
|
113 |
-
|
114 |
-
Jason.encode!(%{error: error})
|
115 |
-
end
|
116 |
end
|
|
|
25 |
end
|
26 |
|
27 |
match _ do
|
28 |
+
handle_response({:not_found, "SRH: Endpoint not found. SRH might not support this feature yet."}, conn)
|
29 |
end
|
30 |
|
31 |
defp do_command_request(conn, success_lambda) do
|
|
|
104 |
|> send_resp(code, create_response_body(resp_data))
|
105 |
end
|
106 |
|
107 |
+
# :data just directly encodes
|
108 |
+
defp create_response_body({:data, data}), do: Jason.encode!(data)
|
|
|
|
|
109 |
|
110 |
+
# :error wraps the message in an error object
|
111 |
+
defp create_response_body({:error, error}), do: Jason.encode!(%{error: error})
|
|
|
|
|
112 |
end
|