result_flow_dio library
A Dart library for handling network requests and responses using Dio. This library provides a set of utilities to simplify the process of making HTTP requests, handling errors, and managing responses. It includes features such as:
- interceptors for request and response handling
- easier error handling
- extensions for easier usage of Dio
- a safe way to handle network errors
Classes
- NetworkErrorFactory
-
NetworkErrorFactory is a singleton class that provides methods to create
instances of
NetworkErrorbased on the type of network error encountered. It uses the NetworkErrorOptions to customize the error messages. The factory methods return instances ofNetworkErrorwith appropriate error messages and codes. - NetworkErrorOptions
- NetworkErrorOptions is used to configure error messages based on the Network Error type. It utilizes the ResultNetworkCode to give a unique identifier to each error while allowing customization of the error message.
- ResultMapperInterceptor
-
ResultMapperInterceptor is a Dio interceptor that transforms the
response and error objects into a
Resulttype. It allows you to handle errors and responses in a more functional way, using theResulttype to represent success and failure. - ResultNetworkCode
- ResultNetworkCode contains the error codes for network requests. These codes are used in to uniquely identify the reason an api request failed.
Extensions
- DioExceptionExtension on DioException
-
DioExceptionExtension is an extension on the
DioExceptionclass from Dio. It provides a method to convert the exception into aResultError. The getResultError method returns aResultErrorbased on the type of DioException encountered. -
ResponseAsyncExtension
on Future<
Response< T> > -
ResponseAsyncExtension is an extension on the Future<Response<T>>
class from Dio. It allows to safely extract
FutureResultfrom an async response. -
ResponseExtenstion
on Response<
T> -
ResponseExtenstion is an extension on the
Responseclass from Dio. It provides a method to extract aResultobject from the response. The withResult method returns a newResponseobject with the data transformed to aResulttype.
Properties
- defaultBadResponseParser ↔ BadResponseParser
-
getter/setter pair
Typedefs
- BadResponseParser = ResultError Function(Response response, {StackTrace? trace})