ValidationException class

Exception for HTTP 422 validation errors with field-specific details.

Thrown when the server rejects a request due to invalid data. The errors map contains field names as keys and error messages as values, enabling precise per-field error display in the UI.

Example:

if (response.statusCode == 422) {
  throw ValidationException(
    message: 'Invalid order data',
    errors: {
      'litres': 'Must be between 1 and 10000',
      'vrn': 'Vehicle registration number is required',
    },
    originalException: dioError,
  );
}

Note: errors is not currently read anywhere in this app — no screen maps it onto per-field form errors yet. It is parsed and preserved on the exception for when that UI is built, not because it is consumed today.

Inheritance

Constructors

ValidationException({String? message, Map<String, dynamic> errors = const <String, dynamic>{}, DioException? originalException, String? errorCode, String? traceId})
Creates a ValidationException with an optional custom message and field-level errors.
const

Properties

errorCode String?
A machine-readable error code from the backend's ErrorResponse envelope (e.g. VALIDATION_ERROR, TOO_MANY_REQUESTS), or null if the response body didn't match that schema.
finalinherited
errors Map<String, dynamic>
Map of field-level validation errors from the backend.
final
hashCode int
The hash code for this object.
no setterinherited
message String
A human-readable description of the error.
finalinherited
originalException DioException?
The underlying Dio exception that caused this network error.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
traceId String?
The backend's request-trace identifier from the ErrorResponse envelope, for correlating this error with server-side logs — or null if the response body didn't match that schema.
finalinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
The string representation of this exception, including Dio-level details.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited