FailureResponse<E> class

Represents a failed API response with error details

Type Parameters: E - Custom error data type (optional)

Equality Note: For proper equality comparison, your custom error type E should implement == and hashCode. Otherwise, equality will use reference comparison (identity).

Example with proper equality:

class LoginError {
  final String? email;
  final String? password;

  LoginError({this.email, this.password});

  // ✅ Implement equality
  @override
  bool operator ==(Object other) =>
    identical(this, other) ||
    other is LoginError &&
      other.email == email &&
      other.password == password;

  @override
  int get hashCode => email.hashCode ^ password.hashCode;
}

// Now FailureResponse equality works correctly
final error1 = FailureResponse<LoginError>(
  400,
  'Validation failed',
  errorData: LoginError(email: 'Invalid email'),
);

final error2 = FailureResponse<LoginError>(
  400,
  'Validation failed',
  errorData: LoginError(email: 'Invalid email'),
);

print(error1 == error2); // true (because LoginError has equality)
Available extensions

Constructors

FailureResponse(int code, String message, {E? errorData})
const

Properties

code int
Error code (HTTP status or custom code)
final
errorData → E?
Optional custom error data
final
hashCode int
The hash code for this object.
no setteroverride
isAuthError bool

Available on FailureResponse<E>, provided by the FailureResponseExtensions extension

Check if this is an authentication error
no setter
isClientError bool

Available on FailureResponse<E>, provided by the FailureResponseExtensions extension

Check if this is a client error (4xx)
no setter
isNetworkError bool

Available on FailureResponse<E>, provided by the FailureResponseExtensions extension

Check if this is a network-related error
no setter
isServerError bool

Available on FailureResponse<E>, provided by the FailureResponseExtensions extension

Check if this is a server error (5xx)
no setter
isValidationError bool

Available on FailureResponse<E>, provided by the FailureResponseExtensions extension

Check if this is a validation error
no setter
message String
Human-readable error message
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

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