Last active
January 19, 2016 00:44
-
-
Save trietphm/26bd24e8d92344b55e28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case get_format(conn) do | |
"json" -> | |
cond do | |
kind == :error -> | |
case reason.__struct__ do | |
Ecto.NoResultsError -> | |
error_view = "404.json" | |
App.Utils.Error.NotFound -> | |
error_view = "404.json" | |
App.Utils.Error.RequestInvalid -> | |
error_view = "400.json" | |
App.Utils.Error.Unauthenticated -> | |
error_view = "401.json" | |
App.Utils.Error.PermissionDenied -> | |
error_view = "403.json" | |
App.Utils.Error.InternalServerError -> | |
error_view = "500.json" | |
_ -> | |
error_view = "500.json" | |
App.Manager.UserManager.send_email_error("#{inspect stack}") | |
end | |
conn | |
|> render(App.Api.ErrorView, error_view, fields: reason) | |
true -> | |
App.Manager.UserManager.send_email_error("#{inspect stack}") | |
conn | |
|> render(App.Api.ErrorView, "500.json", fields: reason) | |
end | |
"html" -> | |
cond do | |
kind == :error -> | |
case reason.__struct__ do | |
Ecto.NoResultsError -> | |
error_view = "404.html" | |
App.Utils.Error.NotFound -> | |
error_view = "404.html" | |
App.Utils.Error.RequestInvalid -> | |
error_view = "400.html" | |
App.Utils.Error.Unauthenticated -> | |
error_view = "401.html" | |
App.Utils.Error.PermissionDenied -> | |
error_view = "403.html" | |
App.Utils.Error.InternalServerError -> | |
error_view = "500.html" | |
_ -> | |
error_view = "500.html" | |
App.Manager.UserManager.send_email_error("#{inspect stack}") | |
end | |
conn | |
|> put_view(App.Frontend.ErrorView) | |
|> render(error_view) | |
true -> | |
App.Manager.UserManager.send_email_error("#{inspect stack}") | |
conn | |
|> put_view(App.Frontend.ErrorView) | |
|> render("500.html") | |
end | |
_ -> | |
conn | |
|> put_view(App.Frontend.ErrorView) | |
|> render("404.html") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment