question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access Operation inside isTokenValidOrUndefined and handleFetch/handleError

See original GitHub issue

When using this library we ran into issue of not being able to access Redux state or dispatch actions inside the TokenRefreshLink because Operation was not accessible inside of it. We had to tweek it a bit so that these functions would pass Operation object.

I believe this use case is quite common because if we store accessToken inside Redux and after refreshing it want to change the state, there’s no possible way to that without having access to context.

This requires minimal changes to the existing code though helps a lot, so it would be nice to have this functionality as part of this library.

export type HandleResponse = (operation: Operation, accessTokenField: string) => void;
export type HandleError = (operation: Operation, err: Error) => void;
export type IsTokenValidOrUndefined = (operation: Operation, ...args: any[]) => boolean;
if (!this.fetching) {
            this.fetching = true;
            this.fetchAccessToken()
                .then(this.handleResponse(operation, this.accessTokenField))
                .then(body => {
                    const token = this.extractToken(body);

                    if (!token) {
                        throw new Error('[Token Refresh Link]: Unable to retrieve new access token');
                    }
                    return token;
                })
                .then(payload => this.handleFetch(operation, payload))
                .catch(error => this.handleError(operation, error))
                .finally(() => {
                    this.fetching = false;
                    this.queue.consumeQueue();
                });
        }

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kharithomascommented, Feb 14, 2022

Update* my configuration of Redux was incorrect - accessing the store directly instead of through operation does work as intended. Tonight, I will still put together a code sandbox to demo what I have.

Original message:

Right, but I can confirm that this setup isn’t working.

Seems the dispatch isn’t getting called correctly from here.

I might be able to put together an example on code sandbox to demo

1reaction
newsiberiancommented, Jan 28, 2022

I think I’ve already updated README. thanks)

Read more comments on GitHub >

github_iconTop Results From Across the Web

React API Handle Error in Fetch Call : TypeError-Cannot read ...
On submitting wrong city name is am getting an error as: TypeError: Cannot read property 'temp' of undefined 22 | .then ...
Read more >
Handling Failed HTTP Responses With fetch() - TJ VanToll
The good is news is fetch provides a simple ok flag that indicates whether an HTTP response's status code is in the successful...
Read more >
How to Correctly Fetch Data in React (fix cannot read property ...
In this video, I give you the four-step process to correctly and safely fetch data asynchronously in React without running into errors.
Read more >
Full React Tutorial #19 - Handling Fetch Errors - YouTube
Hey gang, in this React tutorial we'll handle any errors from the fetch request we made earlier & output any erors in the...
Read more >
Error handling while using native fetch API in JavaScript
We will see, how to handle fetch API errors using promises and async await syntax in JavaScript.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found