ApiError class sealed

Type-safe error hierarchy for keystone_network

Replaces generic FailureResponse with structured error types so screens can respond specifically to each error kind.

Example:

result.when(
  failed: (error) => switch (error) {
    ValidationError(:final fields) => showFieldErrors(fields),
    UnauthorizedError()            => redirectToLogin(),
    ServerError(:final statusCode) => showServerError(statusCode),
    _                              => showGenericError(error.message),
  },
  networkError: (_) => showNoInternet(),
  success: (data)   => render(data),
  loading: ()       => shimmer(),
  idle: ()          => const SizedBox.shrink(),
);
Implementers
Available extensions

Constructors

ApiError.app({required String message})
Application-level / custom error
const
factory
ApiError.badCertificate()
SSL / TLS certificate verification failure
const
factory
ApiError.badRequest({String? message})
400 – malformed request
const
factory
ApiError.cancelled()
Request was cancelled via CancelToken
const
factory
ApiError.conflict({String? message})
409 – resource conflict
const
factory
ApiError.forbidden()
403 – authenticated but not permitted
const
factory
ApiError.methodNotAllowed()
405 – HTTP method not allowed
const
factory
ApiError.network({String? message})
No internet / connection refused / connection reset
const
factory
ApiError.notFound()
404 – resource not found
const
factory
ApiError.server({int? statusCode, String? message})
5xx – server-side failure
const
factory
ApiError.timeout()
Connection / send / receive timeout
const
factory
ApiError.unauthorized()
401 – token missing, expired, or invalid
const
factory
ApiError.unknown({String? message})
Unknown / unclassified error
const
factory
ApiError.validation({required Map<String, List<String>> fields, String? message})
422 – validation failed; fields maps field name → list of messages
const
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
isAuthError bool

Available on ApiError, provided by the ApiErrorX extension

True for auth errors (401 / 403)
no setter
isClientError bool

Available on ApiError, provided by the ApiErrorX extension

True for any 4xx client error
no setter
isNetworkRelated bool

Available on ApiError, provided by the ApiErrorX extension

True for any connectivity-related error (NetworkError, TimeoutError, BadCertificateError, CancelledError)
no setter
isServerError bool

Available on ApiError, provided by the ApiErrorX extension

True for any 5xx server error
no setter
message String
Human-readable description of the error
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

maybeWhen<R>({R network(NetworkError e)?, R timeout(TimeoutError e)?, R badCertificate(BadCertificateError e)?, R cancelled(CancelledError e)?, R unauthorized(UnauthorizedError e)?, R forbidden(ForbiddenError e)?, R badRequest(BadRequestError e)?, R notFound(NotFoundError e)?, R methodNotAllowed(MethodNotAllowedError e)?, R conflict(ConflictError e)?, R validation(ValidationError e)?, R server(ServerError e)?, R app(AppError e)?, R unknown(UnknownError e)?, required R orElse(ApiError e)}) → R

Available on ApiError, provided by the ApiErrorX extension

Partial match — handle what you care about, delegate the rest
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
when<R>({required R network(NetworkError e), required R timeout(TimeoutError e), required R badCertificate(BadCertificateError e), required R cancelled(CancelledError e), required R unauthorized(UnauthorizedError e), required R forbidden(ForbiddenError e), required R badRequest(BadRequestError e), required R notFound(NotFoundError e), required R methodNotAllowed(MethodNotAllowedError e), required R conflict(ConflictError e), required R validation(ValidationError e), required R server(ServerError e), required R app(AppError e), required R unknown(UnknownError e)}) → R

Available on ApiError, provided by the ApiErrorX extension

Exhaustive pattern-match helper

Operators

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