-
Notifications
You must be signed in to change notification settings - Fork 42
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
UnhandledPromiseRejection when returing Promise.reject
on interceptor
#87
Comments
Hi, thanks for raising this issue. You're right, response interceptors returning a promise are not correctly handled at the moment. I'll fix this. |
Hi, I published This still does not implement correct interceptor behavior, as the result of the |
Hi @kingjan1999. I've installed the |
Hello, I am also trying to test response interceptors. My test is expecting the function-under-test to throw an error, which is what I believe If I'm testing it incorrectly, please let me know, but here is what I'm doing: it('will throw unauthorized if the status is 401', async () => {
await expect(() => {
const promise = service.getTheThing()
mockAxios.mockError({ response: { status: 401, data: {} }})
return promise
}).rejects.toThrow(UnauthorizedError)
}) The interceptors: axios.interceptors.response.use((response) => {
return response
}, (error: AxiosError) => {
if (error?.response?.status) {
// This function just returns the appropriate error object to be thrown by Promise.reject()
return Promise.reject(this.checkExceptionForStatus(error))
}
return Promise.reject(error)
})
|
@rosstroha I think you stumbled about the behavior I described above with "interceptors are not corrected properly". The current implementation in |
Fair enough :) Thank you @kingjan1999! |
I'm trying to test my interceptor logic, whether calling the error reporter (like Sentry), showing toast error, and resetting the auth state if we received a 401 response from our server. The problem that we're facing is that we got the following error every time we ran the test:
Based on Interceptors Docs we need to return a rejected promise on the second parameter (onRejected) for the interceptor, but when I remove the
Promise.reject
calls (just returning the error), the test successfully ran.But that turns out to break my app.
Additional info that might help
Any idea how I test my interceptor logic without breaking my app? Thanks in advance!
The text was updated successfully, but these errors were encountered: