You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Axios instance call doesn't return when called from within a custom class. I suspect it's related to the internal this keyword.
To Reproduce
The custom Axios class:
classAxios{
#instance: AxiosInstanceconstructor({ baseURL }: Config){this.#instance=axios.create({
baseURL,headers: {'Content-Type': 'application/json'},})this.#setupInterceptors()}
...
async #interceptResponseError(error: AxiosError,): Promise<AxiosError|AxiosResponse>{if(error.response.status===401){awaitrefreshAuthorization()returnawaitthis.#instance(error.config)// This never returns}returnawaitPromise.reject(error.response)}}exportdefaultAxios
Expected behavior
I would expect this code to work without errors and if it's necessary to use this internally I would somehow make it bound permanently so that it doesn't break when used with classes.
I've confirmed that it's not a problem with my code by moving the const instance = axios.create outside of class and using this variable instead of this.#instance. It does make the code work, but it creates a monolith which I wanted to avoid.
The text was updated successfully, but these errors were encountered:
Describe the bug
Axios instance call doesn't return when called from within a custom class. I suspect it's related to the internal
this
keyword.To Reproduce
The custom Axios class:
Expected behavior
I would expect this code to work without errors and if it's necessary to use
this
internally I would somehow make it bound permanently so that it doesn't break when used with classes.Environment
Additional context/Screenshots
I've confirmed that it's not a problem with my code by moving the const instance = axios.create outside of class and using this variable instead of this.#instance. It does make the code work, but it creates a monolith which I wanted to avoid.
The text was updated successfully, but these errors were encountered: