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 NetworkError based on the type of network error encountered. It uses the NetworkErrorOptions to customize the error messages. The factory methods return instances of NetworkError with 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 Result type. It allows you to handle errors and responses in a more functional way, using the Result type 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 DioException class from Dio. It provides a method to convert the exception into a ResultError. The getResultError method returns a ResultError based 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 FutureResult from an async response.
ResponseExtenstion on Response<T>
ResponseExtenstion is an extension on the Response class from Dio. It provides a method to extract a Result object from the response. The withResult method returns a new Response object with the data transformed to a Result type.

Properties

defaultBadResponseParser BadResponseParser
getter/setter pair

Typedefs

BadResponseParser = ResultError Function(Response response, {StackTrace? trace})