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 (authHandler.usesAuth &&
      error.response?.statusCode == HttpStatus.unauthorized) {
    try {
      final response = await authHandler.refreshTokenCallback(error);

      return response != null
          ? handler.resolve(response)
          : handler.next(error);
    } catch (e) {
      print(e);
    }
  }

  await exceptionHandler.handle(error, extra: error.requestOptions.extra);

  return handler.next(error);
}