Controllers generated with
mix phx.gen.json respond with 422 status for changeset errors, whereas HTML controllers, generated with
mix phx.gen.html respond with 200. I assume this is intentional, curious about the reasoning behind it. I always thought it was conventional to respond with 4xx status in the case of invalid input.
I’ve been using Unpoly, a JS library that merges HTML responses into the dom of the existing page (similar in concept to Turbolinks). Unpoly expects 4xx responses for invalid form submissions so I’ve been modifying my controllers to provide 422 responses. I’m curious why the generators don’t do this by default.