-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}.