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
I'm using the Fetch API client and have been trying to set a timeout time on requests, but I'm running into issues and can't seem to figure it out. Has anyone managed to get this working, or can you point me in the right direction?
constabortControllers=newMap<string,AbortController>();constcreateAbortKey=(request: {method: string;url: string})=>{return`${request.method}:${request.url}`;};client.interceptors.request.use((request)=>{constcontroller=newAbortController();constsignal=controller.signal;abortControllers.set(createAbortKey(request),controller);setTimeout(()=>{controller.abort();console.error("Request timed out");},15000);request.signal=signal;// gives error "Cannot set property signal of #<Request> which has only a getter"returnrequest;// return { ...request, signal }; // also doesn't work, this causes the requests to look like http://localhost:3000/[object%20Object]});client.interceptors.response.use((response,request)=>{// clean up when we get a response, could probably improved to also remove the setTimeoutabortControllers.delete(createAbortKey(request));returnresponse;});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using the Fetch API client and have been trying to set a timeout time on requests, but I'm running into issues and can't seem to figure it out. Has anyone managed to get this working, or can you point me in the right direction?
Beta Was this translation helpful? Give feedback.
All reactions