aboutsummaryrefslogtreecommitdiff
path: root/apps/dreki_web/src/ui/dreki_web_ui_error.erl
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dreki_web/src/ui/dreki_web_ui_error.erl')
-rw-r--r--apps/dreki_web/src/ui/dreki_web_ui_error.erl14
1 files changed, 14 insertions, 0 deletions
diff --git a/apps/dreki_web/src/ui/dreki_web_ui_error.erl b/apps/dreki_web/src/ui/dreki_web_ui_error.erl
new file mode 100644
index 0000000..ccda150
--- /dev/null
+++ b/apps/dreki_web/src/ui/dreki_web_ui_error.erl
@@ -0,0 +1,14 @@
+-module(dreki_web_ui_error).
+-behaviour(cowboy_handler).
+-export([init/2]).
+
+init(Req, not_found) ->
+ reply(Req, 404, <<"Not Found">>, undefined);
+init(Req, State = #{code := Code, status := Status}) ->
+ reply(Req, Code, Status, maps:get(message, State, undefined)).
+
+reply(Req0, Code, Status, Msg) ->
+ Assigns = [{"message", Msg}, {"status", Status}],
+ Html = dreki_web_ui:render(Req0, error_dtl, Assigns),
+ Req = dreki_web_ui:reply_html(Req0, Code, Html),
+ {ok, Req, undefined}.