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

Enhancement: Automatically return 400 response if param validation fails #1327

Open
a-alhusaini opened this issue Jun 29, 2023 · 1 comment

Comments

@a-alhusaini
Copy link

Right now, if a validation fails the developer needs to write a block similar to this one in order to return a response:

unless params.valid?
  response.puts {errors: params.errors}.to_json
  response.status_code 400
end

A 400 response with the appropriate body should be the default procedure should a call to validate! fail. This simplifies error handling especially in situations where the response is json because in that scenario, you rarely want to return custom output in situations where the client created an invalid request.

In situations where the user has a page then we can easily return a default error page. We should have default error pages anyway so we may as well add them while we add this enhancement to controller error handling.

@hugopl
Copy link
Contributor

hugopl commented Oct 20, 2023

If you implement your own Error pipe and use it instead of Amber::Pipe::Error you can have what you want. Not ideal since you end up needing to copy some code from Amber::Pipe::Error but at least it's possible to do what you want.

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