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(),
);
Constructors
- ApiError.app({required String message})
-
Application-level / custom error
constfactory
- ApiError.badCertificate()
-
SSL / TLS certificate verification failure
constfactory
- ApiError.badRequest({String? message})
-
400 – malformed request
constfactory
- ApiError.cancelled()
-
Request was cancelled via CancelToken
constfactory
- ApiError.conflict({String? message})
-
409 – resource conflict
constfactory
- ApiError.forbidden()
-
403 – authenticated but not permitted
constfactory
- ApiError.methodNotAllowed()
-
405 – HTTP method not allowed
constfactory
- ApiError.network({String? message})
-
No internet / connection refused / connection reset
constfactory
- ApiError.notFound()
-
404 – resource not found
constfactory
- ApiError.server({int? statusCode, String? message})
-
5xx – server-side failure
constfactory
- ApiError.timeout()
-
Connection / send / receive timeout
constfactory
-
401 – token missing, expired, or invalid
constfactory
- ApiError.unknown({String? message})
-
Unknown / unclassified error
constfactory
-
ApiError.validation({required Map<
String, List< fields, String? message})String> > -
422 – validation failed;
fieldsmaps field name → list of messagesconstfactory
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 errorno 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 errorno 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 - 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 - Exhaustive pattern-match helper
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited