Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(interceptor): handle the error in the same interceptor #6269

Open
wants to merge 2 commits into
base: v1.x
Choose a base branch
from

Conversation

Tackoil
Copy link

@Tackoil Tackoil commented Feb 29, 2024

fixes: #4537

When handling error in asynchronous request interceptors, onRejected always handle the error in the next interceptors. So I make a fix about this case. Detail context is in the issue.

During the fix, I found that it will cause a TypeError when an error occurred in the request interceptors, because the config is lost during the promise chain.

TypeError: Cannot read properties of undefined (reading 'cancelToken')

So we can define a new onRejected handler behavior. If users want to continue the request, they should return a default config in the onRejected function.

@Tackoil
Copy link
Author

Tackoil commented Mar 1, 2024

To fix the lost of config in promise chain, I made a change to support it.

        promise = promise
            .then(chain[i++]) // push the onResolved handler. If an error occur, it will jump to the catch function.
            .then(result => {prevResult = result ? result : prevResult}) // update the result
            .catch(chain[i++]) // push the onRejected handler
            .then(() => prevResult); // pass the result to the next interceptor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The error handling function in request interceptors may not work as expect.
1 participant