Handling "route doesn't" for a json request -- don't work

My ErrovView

defmodule MyApp.ErrorView do
  use MyApp.Web, :view

  def render("404.json", _assigns) do
    "Page not found - my custom json handler"
  end

However, when I call a route which doesn’t exist:

curl -H "Content-Type: application/json" -X GET http://localhost:4000/some_random_route123

config:

config :my_app, MyApp.Endpoint,
  render_errors: [view: MyApp.ErrorView, accepts: ~w(html json)],

it returns a long html page with an exception and all the details. Why not just a string “Page not found - my custom json handler”?

And how can I handle all such requests to non existing routes?

Solved already.

Even if you solve your problem on your own, it’s always nice to provide the actual solution so other people having that problem may try your solution for their case. Finding only a post that asks about the same problem that you have but that is closed with only a single “solved” is extremely demotivating.

7 Likes

yeah, my task is to boost your motivation.

who will boost mine?