onError method

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

Called when an exception was occurred during the request.

Implementation

@override
void onError(DioException err, ErrorInterceptorHandler handler) {
  final options = err.requestOptions;
  final requestPath = '${options.baseUrl}${options.path}';

  // Check for per-request override
  final bool currentLogResponseError =
      options.extra['logResponseError'] ?? logResponseError;

  // Log the error request and error message
  if (currentLogResponseError) {
    logDebug('onError: ${options.method} request => $requestPath',
        level: Level.error);
    logDebug('onError: ${err.error}, Message: ${err.message}',
        level: Level.debug);
  }

  // Call the super class to continue handling the error
  return super.onError(err, handler);
}