Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending properly formatted 404 Not Found #188

Open
strzibny opened this issue Mar 14, 2019 · 2 comments
Open

Sending properly formatted 404 Not Found #188

strzibny opened this issue Mar 14, 2019 · 2 comments

Comments

@strzibny
Copy link
Contributor

strzibny commented Mar 14, 2019

Hello, first thanks for this library, looking great.

I am trying to test 404 endpoints and realized that jsonapi maybe does not catch Ecto.NoResultsError and does not show proper 404 error.

It should show a JSON:API spec formatted error as for any other:

{"errors":[{"status":"404","title":"Page not found"}]}

am I not realizing something? It feels like it counts on Phoenix to serve 404 error which is without the formatted message above.

@jherdman
Copy link
Contributor

Interesting. In a project I have I see the following:

{"errors":[{"status":"404","title":"Page not found"}]}

I have a bit of manual error set up though. I'm sure we can do something to improve this situation.

@strzibny
Copy link
Contributor Author

Just for anybody coming here I can achieve this with the following:

defmodule Web.ErrorView do
  use Web, :view

  # 404 Not Found following JSON:API
  def render("404.json", _assigns) do
    Jason.encode!(%{errors: [%{status: "401", title: "Not Found"}]})
  end
end

It works, but won't allow me to easily test this in a controller test, because I need to catch the exception. Maybe jsonapi could catch the exception before Phoenix does and this way it would work? I am sorry I am just one-week-in in Phoenix so a bit hard for me to figure this out on my own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants