You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Validations: Configure which status codes to rescue from
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`.
0 commit comments