Skip to content

UnhandledPromiseRejection when returing Promise.reject on interceptor #87

@ashalfarhan

Description

@ashalfarhan

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:

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "AxiosError".] 
{
  code: 'ERR_UNHANDLED_REJECTION'
}

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions