Skip to content

Conversation

@seanpdoyle
Copy link
Contributor

The problem

The established convention is for resources to rescue from 422 Unprocessable Content responses by raising an
ActiveResource::ResourceInvalid exception. The mixed-in ActiveResource::Validation module rescues from
ActiveResource::ResourceInvalid, then parses error messages from the response body.

This works for many remote services, but there are other status codes that remote services might respond with that include resource-specific error messages.

For example, a service could respond with a more generic status of 400 Bad Request to indicate that the request was invalid. If the response includes error messages, it could be important to import them into the resource's error messages.

The proposal

Introduce the Base.remote_errors attribute (named to match the style of the @remote_errors instance variable and the #load_remote_errors private method) to control which errors to rescue from. The default value remains ActiveResource::ResourceInvalid.

The problem
---

The established convention is for resources to rescue from `422
Unprocessable Content` responses by raising an
`ActiveResource::ResourceInvalid` exception. The mixed-in
`ActiveResource::Validation` module rescues from
`ActiveResource::ResourceInvalid`, then parses error messages from the
response body.

This works for many remote services, but there are other status codes
that remote services might respond with that include resource-specific
error messages.

For example, a service could respond with a more generic status of `400
Bad Request` to indicate that the request was invalid. If the response
includes error messages, it could be important to import them into the
resource's error messages.

The proposal
---

Introduce the `Base.remote_errors` attribute (named to match the style
of the `@remote_errors` instance variable and the `#load_remote_errors`
private method) to control which errors to rescue from. The default
value remains `ActiveResource::ResourceInvalid`.
@seanpdoyle seanpdoyle force-pushed the validation-error-classes branch from 8ac5eb0 to 62bee80 Compare October 23, 2025 19:19
@rafaelfranca rafaelfranca merged commit c0fea1d into rails:main Oct 23, 2025
19 checks passed
@seanpdoyle seanpdoyle deleted the validation-error-classes branch October 23, 2025 20:21
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.

2 participants