ApiException class
A Failure, thrown.
Every request returns Either, which is right for one call and clumsy
for a flow of several, each depending on the last: the folds nest. Throw
out of the flow with ApiResultOrThrow.orThrow instead, and turn the
whole thing back into an Either at its edge with guardApi:
Future<Either<Failure, Receipt>> checkout(Cart cart) => guardApi(() async {
final order = await api.postAs(endpoint: '/orders', parser: Order.fromJson,
data: cart.toJson()).orThrow();
final payment = await api.postAs(endpoint: '/orders/${order.id}/pay',
parser: Payment.fromJson).orThrow();
return api.getAs(endpoint: '/receipts/${payment.receiptId}',
parser: Receipt.fromJson).orThrow();
});
The first failure stops the flow and becomes the result, exactly as it came back from the client.
- Implemented types
Constructors
- ApiException(Failure failure)
-
const
Properties
- data → Object?
-
The raw response body — see Failure.data.
no setter
- errorType → ErrorSource
-
What kind of failure it was — see Failure.errorType.
no setter
- failure → Failure
-
The failure the request returned, unchanged.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- message → String
-
The user-facing message — see Failure.message.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- statusCode → int?
-
The literal HTTP status — see Failure.statusCode.
no setter
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.
inherited