Skip to content

Introduce Rack::BadRequest exception. #1996

@ioquatix

Description

@ioquatix

Something like:

class Rack::BadRequest < StandardError
  def initialize(message, status = 400)
    super(message)
    @status = status
  end
  attr :status
end

This class would be used to indicate failures within Rack, and servers should be able to catch it and correctly map it to a failed response.

There are places in the multipart parsing code and Rack::Request where various conditions can be the result of a bad client HTTP request. It feels like it would be useful to have an exception that indicates that. The current situation right now, is we may raise an IOError or some other exception which becomes a 500 Internal Server Error, which while correct in a way (the server basically blew up), doesn't really reflect the nature of the "request being invalid" - e.g. a bad request, preconditions failed, etc.

See #1994 (comment) for an example use case.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions