I started a phoenix project without using the --no-html option, and am now trying to ensure that the 404 and 500 errors render as JSON. The project started on Phoenix 1.1.0, and has been updated to 1.1.4.
I've modified the config/config.exs file's render_errors (under config :my_app, MyApp.Endpoint) to be [view: MyApp.ErrorView, format: "json", accepts: ~w(json)].
The routes all accept JSON and currently none of them accept HTML.
I've modified the web/web.ex file to remove the use Phoenix.HTML in the view function, and I've modified the web/views/error_view.ex to render JSON.
However at this point both 404 and 500 errors still return html.
Did you update your config.exs?
config :my_app, MyApp.Endpoint,
# ...
render_errors: [accepts: ~w(html json)],
# ...
And what kind of html is returned? Maybe it is the phoenix debug page for your dev environment which you can disable in config/dev.exs
config :my_app, MyApp.Endpoint,
# ...
debug_errors: false,
# ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With