onError method

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

Called when an exception was occurred during the request.

Implementation

@override
void onError(DioException err, ErrorInterceptorHandler handler) {
  final requestId = err.requestOptions.headers['X-Request-ID'];
  final timestamp = err.requestOptions.headers['X-Request-Timestamp'];

  if (LokotroPayEnv.debugMode) {
    debugPrint('[Lokotro Pay Interceptor] Error: ${err.type} for request $requestId');
    debugPrint('[Lokotro Pay Interceptor] Error message: ${err.message}');
    debugPrint('[Lokotro Pay Interceptor] Response time: ${_calculateResponseTime(timestamp)}ms');
  }

  // Enhance error with additional context
  final enhancedError = _enhanceError(err);

  super.onError(enhancedError, handler);
}