onError method

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

Handles errors during HTTP requests.

Logs error details including request method, path, error type, and message.

Implementation

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

  // Log error details:
  // - Request method and path
  logDebug('onError: ${options.method} request => $requestPath',
      level: LogLevel.error);
  // - Error type and message
  logDebug('onError: ${err.error}, Message: ${err.message}',
      level: LogLevel.debug);
  logDebug(_lineChar);
  logDebug('\n');
  return super.onError(err, handler);
}