resilify 1.0.4
resilify: ^1.0.4 copied to clipboard
Unified Result-based API handling for Dart & Flutter — works with http, Dio, Retrofit, Chopper, and WebSocket. No exceptions. Just results.
Changelog #
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
1.0.4 #
Added #
-
Failure.retryAfter— aDuration?field onFailurethat surfaces the server's back-off hint from aRetry-AfterHTTP header. Populated automatically for 429 / 5xx responses by bothHttpResultHandlerand the Dio integration'smapDioException. Pair withRetryHelper.retry'sdelayparameter to honor the server's wait time exactly:result.errorOrNull?.retryAfter // Duration(seconds: 30) when present -
Failure.parseRetryAfter(String?)— static helper that converts the seconds form of an HTTPRetry-Afterheader into aDuration. Returnsnullfor null / blank / non-numeric input; clamps negatives to zero. The HTTP-date form is intentionally left to callers so the core library stays free ofdart:io. -
platforms:declaration inpubspec.yaml(Android, iOS, Linux, macOS, Windows) so pub.dev surfaces verified platform support on the package page. -
documentation:link inpubspec.yamlpointing at the published dartdoc. -
Smoke tests for
HttpResultHandlercovering JSON GET/POST round-trips, query parameter merging, default-header propagation, 404 / 429 / 5xx mapping,Retry-Afterextraction, and parsing failures — closing the integration test gap flagged in the 1.0.3 audit.
Fixed #
- Trailing-comma lint warnings in
dio_result.dartandlogger.dartso the package now ships with a cleandart analyze.
1.0.3 #
Added #
Result.fromNullable<T>(T?, {Failure Function()? onNull})— bridge nullable APIs (cache lookups,firstWhereOrNull, etc.) into aResult<T>in one call.Result.zip2andResult.zip3— combine multiple results into a record (Result<(A, B)>/Result<(A, B, C)>), short-circuiting on the first failure left-to-right. Handy for parallel fetches withFuture.wait.Result.collect<T>(Iterable<Result<T>>)— fold a list of results into a singleResult<List<T>>, returning the first failure encountered.recoverWithextension onFuture<Result<T>>— likerecover, but the fallback callback may itself return aResult(so a fallback network call that also fails is surfaced as the final error).mapErrorAsyncextension onFuture<Result<T>>— async counterpart to the synchronousResult.mapError.
Changed #
RetryHelper.retrynow acceptsattemptTimeout. When set, each attempt is wrapped inFuture.timeout; an exceeded timeout is converted into anError(Failure.timeout())and goes through the normalretryIf/maxAttemptsmachinery.
1.0.2 #
Added #
- New
Failurenamed constructors:Failure.forbidden(403),Failure.conflict(409), andFailure.rateLimit(429). Failure.fromStatusCode(int)— picks the most specific named constructor for a given HTTP status, falling back tobadResponsefor other 4xx andserverErrorfor other 5xx.Failure.is4xx,Failure.is5xx, andFailure.isRetryablegetters — drop-in predicates forRetryHelper.retryIf.onCompleteextension onResult<T>— finally-style hook that fires for bothSuccessandError.flatten()extension onResult<Result<T>>— collapses one layer of nesting thatflatMapchains often produce.
Changed #
RetryHelper.retrynow acceptsmaxDelayto cap the wait between attempts andjitter(with an optionalRandom) to spread retries and prevent thundering-herd retry storms. Both default to no-op behavior, so existing call sites are unaffected.
1.0.1 #
Added #
Result.tryRunandResult.tryRunAsync— bridge throwing code into aResult<T>without writing try/catch at call sites. Both accept an optionalonErrorto translate the caught object into a domain-specificFailure.mapErroronResult<T>— transform the wrappedFailurewithout touching the success path. Useful for translating low-level transport failures into domain failures.errorOrThrowextension — symmetric counterpart togetOrThrow, returning the wrappedFailureor throwing aStateErroronSuccess.
1.0.0 — Initial release #
Added #
-
Core
- Sealed
Result<T>withSuccess<T>andError<T>variants (Dart 3). - Structured
Failurevalue type with named constructors:network,timeout,badResponse,parsing,unauthorized,notFound,serverError,cancelled,unknown. - Synchronous extensions:
isSuccess,isError,dataOrNull,errorOrNull,getOrElse,getOrThrow,onSuccess,onError. when,fold,map,flatMaponResult<T>.- Async helpers on
Future<Result<T>>:mapAsync,flatMapAsync,recover. - Stream helpers on
Stream<Result<T>>:mapStream,whereSuccess,whereError,dataStream,listenResult. - List helpers on
Result<List<T>>:mapList,filter,whereResult,firstOrError. RetryHelper.retrywith exponential backoff, predicate-based retry, and per-attempt observer.
- Sealed
-
Integrations (each opt-in via its own barrel file)
resilify_http.dart—HttpResultHandlerforpackage:http.resilify_dio.dart—DioResultHandler(incl.upload/downloadwith progress) andResultLoggerInterceptor.resilify_retrofit.dart—.toResult()on Retrofit-generated futures.resilify_chopper.dart—.toResult()on ChopperResponse<T>futures with pluggable failure mappers.resilify_websocket.dart—WebSocketResultHandler<T>with auto-reconnect and exponential backoff.