onError method

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

Intercepts Dio errors and replaces them with typed app exceptions.

Maps err to an AppException subclass, embeds it in a new DioException on the error field, and passes it to the next handler via handler.next. The Dio error structure is preserved so downstream interceptors that expect DioException continue to work correctly.

Implementation

@override
void onError(DioException err, ErrorInterceptorHandler handler) {
  final AppException appException = _mapDioExceptionToAppException(err);

  final DioException newException = DioException(
    requestOptions: err.requestOptions,
    response: err.response,
    type: err.type,
    error: appException,
    message: err.message,
    stackTrace: err.stackTrace,
  );

  handler.next(newException);
}