EpochtalkServerWeb.ErrorView (epochtalk_server v0.1.0)

Renders and formats error data, in JSON format for frontend

Link to this section Summary

Functions

The resource name, as an atom, for this view

Renders the given template locally.

Render uses template_not_found when Phoenix cannot find the specified template, this has been modified to handle and all types of errors. Epochtalk Server sends all errors through this view to render a consistent error JSON.

Link to this section Functions

The resource name, as an atom, for this view

Link to this function

render(template, assigns \\ %{})

Renders the given template locally.

Link to this function

template_not_found(template, assigns)

@spec template_not_found(Phoenix.Template.name(), map()) :: no_return()

Render uses template_not_found when Phoenix cannot find the specified template, this has been modified to handle and all types of errors. Epochtalk Server sends all errors through this view to render a consistent error JSON.

example

Example

iex> EpochtalkServerWeb.ErrorView.render("500.json")
%{error: "Internal Server Error", message: "Request Error", status: 500}
iex> EpochtalkServerWeb.ErrorView.render("400.json")
%{error: "Bad Request", message: "Request Error", status: 400}
iex> EpochtalkServerWeb.ErrorView.render("404.json")
%{error: "Not Found", message: "Request Error", status: 404}
iex> EpochtalkServerWeb.ErrorView.render("401.json")
%{error: "Unauthorized", message: "Request Error", status: 401}
iex> EpochtalkServerWeb.ErrorView.template_not_found("DoesNotExist.json", %{message: "Custom Error Message", status: 500})
%{error: "Internal Server Error", message: "Custom Error Message", status: 500}
iex> EpochtalkServerWeb.ErrorView.template_not_found("DoesNotExist.json", %{message: "Custom Error Message", status: 404})
%{error: "Not Found", message: "Custom Error Message", status: 404}