No headers were found in the response from Apollo Client's RetryLink

I have added a RetryLink to my Apollo Client in the following way:

const retryLink = new RetryLink({
  attempts: (count, _, error) => {
    return count <= 5 && !!error;
  },
  delay: (count, operation) => {
    const {response: { headers }} = operation.getContext();
    // headers is always empty
    return count * 1000 * Math.random();
  }
});

The objective is to adjust the delay by using a custom header sent by the server (which has rate limiting). However, the headers field in the response always remains empty. The response itself looks like this:

{
  body: (...)
  bodyUsed: true
  headers: Headers {}
  ok: false
  redirected: false
  status: 429
  statusText: ""
  type: "cors"
  url: "https://graphql.endpoint.co/"
}

If I switch to another link, the header is present as expected. This alternative approach works:

const afterwareLink = new ApolloLink((operation, forward) => {
  return forward(operation).map(response => {
    const context = operation.getContext();
    const {
      response: { headers }
    } = context;

    if (headers) {
      console.log(headers.get('Retry-After'));
    }

    return response;
  });
});

To provide an overview, here is how the client setup looks like:

const createApolloClient = () => {
  return new ApolloClient({
    ssrMode: typeof window === 'undefined',
    link: from([retryLink, authLink.concat(httpLink)]),
    cache: new InMemoryCache()
  });
};

Is there a way to access the response headers within a RetryLink? Any insights would be appreciated.

Answer №1

Every now and then, a good night's rest does the trick.

The hyperlink is functioning as expected. The issue arose from the fact that access-control-expose-headers did not encompass Retry-After. What caught me off guard was the revelation that while developer tools display all headers sent by the server, scripts can only utilize headers specified in access-control-expose-headers.

Hence, why the header consistently returned null.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I want to import JSON information from a file to display on my website

I am trying to implement a JSON array on my webpage when a button or image is clicked. Here is the array I have: var products = [ { "productID":"1", "name":"Stark Navy", "url": "stark.jpg", "description": "Waterproof, double velcro straps", "price": " ...

Is there a way to see the countdown timers in Angular 7?

Is there a way for me to view my timer's countdown as it starts? I have attempted to bind it to a variable, but all I see is [object Object]: setTime(time) { if (this.settime >= 5 ) { this.currentTime = time; this.alerttime = thi ...

What is the process for converting an Angular UTC timestamp to a local timestamp?

Is it possible to convert a UTC timestamp to a local time timestamp using any function or method? I am sending the timestamp to angular moments, but the server's timestamp is in UTC. ...

Showing a message only when there is input in the search bar using jQuery

I'm currently working with a Google Instant style search script that is written in jQuery and queries a PHP file. The issue I am facing is that even when the search box is empty and there are no search terms, the script still displays a message saying ...

Transform an array of dates containing time zones into Coordinated Universal Time (UTC) or Greenwich Mean Time (

So, I am facing an issue with a plugin that generates an array of dates without the ability to modify it. This plugin is embedded in the app's core and pulls data from a central database. The problem lies in the fact that the array of dates includes ...

What is the correct method for iterating through this array of objects and eliminating those with either null or empty item.text values?

Currently, I am working with the following Array: const contactInfo = computed(() => { return [ { id: 'address', icon: 'detail/clubLocation', text: `${props.data.contactInfo.address}` ...

Effortlessly uploading large files using axios

I am currently facing an issue and I am seeking assistance. My goal is to implement file chunk upload using axios, where each chunk is sent to the server sequentially. However, the requests are not being sent in order as expected. Below is a snippet of m ...

Ways to effectively utilize jQuery objects as arguments in the delegate function

When working with delegate and multiple selectors, you can use the following syntax: $(contextElement).delegate('selector1, selector2' , 'eventName', function(){ //blabla }); In projects where managing DOM elements is important, stori ...

Switching the background image when hovering over a list element

Looking at the screenshot, it's clear that there is an unordered list with a background image set on the div. What I am trying to achieve is to have the background image change whenever I hover over a list item. Each list item should trigger a differe ...

The message of error is undetermined

Can someone help me with using the errorMessage object from routes in a partial? I have attempted to implement it as shown below: Route:- const express = require("express"); const router = express.Router(); const Character = require("../models/character" ...

Tips for verifying a missing 'Access-Control-Allow-Origin' header error

Is it feasible, while working with XMLHttpRequest in JavaScript, to differentiate between these two types of errors: GET request completely failed/No 'Access-Control-Allow-Origin' header? https://i.sstatic.net/Zas2z.png It seems that the readyS ...

Guide to emphasize the active navigation tab in a particular scenario

Utilizing this template for JavaScript to choose the appropriate navigation using JQuery, with reference to this API. Snippet of my current code: index.php <html> <head> <title>ChillSpot Alpha 1.2.3</title> &l ...

Tips for efficiently handling MongoDB data on the server side with socket management

My venture into using Socket.io for the first time has led me to create a simple game. At this point, I have a MongoDB database structured as follows: | Sessions | | Users | | Games | |-----------| |------------| |-----------| | * _id | ...

Tips on making the form validation script operational

After developing a form alongside a form validation script to ensure that all fields are completed, the name and city sections only contain letters, while the age and phone sections solely include numbers, issues have arisen. It seems that despite the cons ...

Pass the JavaScript variable and redirect swiftly

One of the functionalities I am working on for my website involves allowing users to submit a single piece of information, such as their name. Once they input their name, it is sent to the server via a post request, and in return, a unique URL is generated ...

Ways to determine the success of $wpdb->query and retrieve the outcome

Currently, I am in the process of developing a WordPress website, I have implemented a form that allows users to make modifications and update the database: Below is the HTML/PHP code snippet: echo '<form class="form-verifdoc" target=&q ...

manipulating child element's innerHTML with javascript

Is there a way to change my icon from expand_more to expand_less in the code below? <li class="dropdown-bt" onclick="dropdown('content');"> <a>dropdown-content <i class="material-icons">expand_more</i></a> </ ...

What is the best way to divide my HTML page in half?

My goal is to display two maps side by side, one on the right and the other on the left. However, when I try to implement this, one map appears on top of the other. I believe that CSS positioning can help me achieve the desired layout, but as a beginner in ...

Using $.bind() on SVG elements causes an error when a new SVG replaces the original one

I have a customized svg where elements are connected to user clicks and keyups. When a user modifies a text field on the website, it automatically updates the corresponding text element within the svg. Similarly, if the user edits the svg, the correspondin ...

The art of blending different inheritance (Styled Elements)

Can components be based on other styled components? Take a look at the code snippets below. I am interested in creating a component like this: const HeaderDropDownLi = styled(DropDownLi, HeaderItem) Both DropDownLi and HeaderItem are derived from a style ...