Skip to content

Wrap Rack parameter parsing errors in Grape::Exceptions::RequestError#2670

Open
ericproulx wants to merge 1 commit intomasterfrom
rack_request_error
Open

Wrap Rack parameter parsing errors in Grape::Exceptions::RequestError#2670
ericproulx wants to merge 1 commit intomasterfrom
rack_request_error

Conversation

@ericproulx
Copy link
Copy Markdown
Contributor

@ericproulx ericproulx commented Apr 3, 2026

Closes #2668

Summary

Replaces five specific Rack-related exception classes with a single Grape::Exceptions::RequestError that forwards the Rack exception's own message directly, removing Grape's translated messages for these cases.

Changes

New: Grape::Exceptions::RequestError

A lightweight wrapper that takes any exception and an optional status: (default 400), forwarding the exception's message as-is.

Removed exception classes

Removed Was raised for
Grape::Exceptions::EmptyMessageBody EOFError
Grape::Exceptions::TooManyMultipartFiles Rack::Multipart::MultipartPartLimitError/TotalPartLimitError
Grape::Exceptions::TooDeepParameters Rack::QueryParser::ParamsTooDeepError
Grape::Exceptions::ConflictingTypes Rack::Utils::ParameterTypeError
Grape::Exceptions::InvalidParameters Rack::Utils::InvalidParameterError

Grape::RACK_ERRORS constant

Centralises the list of rescuable Rack exceptions. On Rack 3, Rack::BadRequest is a marker module included by all bad-request exception classes — a single rescue entry covers them all. On Rack 2, each class is listed individually.

# Rack 3
RACK_ERRORS = [EOFError, Rack::BadRequest]

# Rack 2
RACK_ERRORS = [EOFError, Rack::Multipart::MultipartPartLimitError, ...]

Grape::RACK_ERRORS is also used in Grape::Middleware::Base#query_params for consistent handling.

Breaking changes

  • The five removed exception classes no longer exist. Rescue Grape::Exceptions::RequestError instead.
  • Error messages for these cases now come directly from Rack rather than Grape's locale file. The corresponding translation keys have been removed from en.yml.

See UPGRADING.md for migration instructions.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

Danger Report

No issues found.

View run

@ericproulx ericproulx force-pushed the rack_request_error branch 2 times, most recently from 4be9fad to 198e7ae Compare April 3, 2026 14:34
Replace five specific exception classes (EmptyMessageBody, TooManyMultipartFiles,
TooDeepParameters, ConflictingTypes, InvalidParameters) with a single
Grape::Exceptions::RequestError that forwards the Rack exception message directly.

On Rack 3, a single `rescue Rack::BadRequest` covers all bad-request errors via
the marker module. On Rack 2, each exception class is listed explicitly in
Grape::RACK_ERRORS.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ericproulx ericproulx force-pushed the rack_request_error branch from 198e7ae to a815bc3 Compare April 3, 2026 16:46
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

Successfully merging this pull request may close these issues.

Grape is failing on latest Rack releases.

2 participants