onRequest method

  1. @override
void onRequest(
  1. RequestOptions options,
  2. RequestInterceptorHandler handler
)
override

Called when the request is about to be sent.

Implementation

@override
void onRequest(RequestOptions options, handler) {
  options.extra.addAll({
    'showInternalServerErrors': exceptionOptions.showInternalServerErrors
  });
  options.extra
      .addAll({'showNetworkErrors': exceptionOptions.showNetworkErrors});
  options.extra.addAll(
      {'showValidationErrors': exceptionOptions.showValidationErrors});

  if (isPreemptivelyRefreshBeforeExpiry &&
      !authOptions.ignoreAuthForPaths.contains(options.path)) {
    try {
      final isExpired = JwtDecoder.isExpired(authHandler.jwt ?? '');

      if (isExpired) {
        authHandler.refreshTokenCallback(options, handler);
      } else {
        handler.next(options);
      }
    } catch (e) {
      print(e);
    }
  } else {
    handler.next(options);
  }
}