onError method

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

Called when an exception was occurred 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) {
      print(e);
    }
  } else {
    await exceptionHandler.handle(error, extra: error.requestOptions.extra);

    handler.next(error);
  }
}