decodeRejection function
The 422 for an error thrown while building a value out of subject.
A generated deserialize that enforces its own constraints throws
ValidationException, and those errors name the field that failed, so they
are handed back one field at a time. Anything else — a missing key, a value
of the wrong type — describes the shape rather than one field, and lands in
the message.
Implementation
Rejection decodeRejection(Object error, {required String subject}) {
if (error is ValidationException) {
return Rejection.unprocessable(
groupValidationErrors(error.errors),
message: 'Validation failed',
);
}
return Rejection.unprocessable(
const {},
message: '$subject does not match the expected shape: $error',
);
}