onError method

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

Called when an exception occurs during the request.

Implementation

@override
void onError(DioException error, handler) async {
  if (isResponseAndRetry &&
      error.response?.statusCode == HttpStatus.unauthorized) {
    try {
      final response =
          await authHandler.refreshTokenCallback(error.requestOptions);

      if (response != null) {
        handler.resolve(response);
      } else {
        handler.next(error);
      }
    } catch (e) {
      debugPrint(e.toString());
    }
  } else {
    handler.next(error);
  }
}