Skip to content

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

Description

@a-alhusaini

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions