onError method

  1. @override
void onError(
  1. DioError err,
  2. ErrorInterceptorHandler handler
)

The callback will be executed on error.

If you want to continue the error , call handler.next.

If you want to complete the response with some custom data directly, you can resolve a Response object with handler.resolve and other error interceptor(s) will be skipped.

If you want to complete the response with an error message directly, you can reject a DioError object with handler.reject, and other error interceptor(s) will be skipped.

Implementation

@override
void onError(DioError err, ErrorInterceptorHandler handler) {
  logPrint('*** Api Error - Start ***:');

  logPrint('URI: ${err.requestOptions.uri}');
  if (err.response != null) {
    logPrint('STATUS CODE: ${err.response?.statusCode?.toString()}');
  }
  logPrint('$err');
  if (err.response != null) {
    printKV('REDIRECT', err.response?.realUri ?? '');
    logPrint('BODY:');
    printAll(err.response?.data.toString());
  }

  logPrint('*** Api Error - End ***:');
  return handler.next(err);
}