Questions tagged [abortcontroller]

AbortController is an interface that allows a DOM request to be aborted before it is completed and is part of the DOM standard. When using this tag, please specify which JavaScript library or environment, such as [reactjs] or [node.js], is being used.

31 questions
10
votes
1 answer

AbortController missing in TypeScript

I am trying to use AbortController in TypeScript. Given this small file: const controller = new AbortController(); I get the following error from TypeScript compiler: src/testAbort.ts:1:24 - error TS2304: Cannot find name 'AbortController'. 1…
Rene Saarsoo
  • 13,580
  • 8
  • 57
  • 85
4
votes
1 answer

React - using AbortController on every request as a custom hook

I have a context provider in my app: export const FormContext = createContext(null); function FormProvider({ caseNumber, children, ...props }: PropsWithChildren) { const { data: {…
Ludwig
  • 1,401
  • 13
  • 62
  • 125
4
votes
1 answer

AbortController.abort(reason), but the reason gets lost before it arrives to the fetch catch clause

I am implementing abortable fetch calls. There are basically two reasons for aborting the fetch on my page: the user decides he/she does not want to wait for the AJAX data anymore and clicks a button; in this case the UI shows a message "call…
3
votes
0 answers

How does AbortController work under the hood?

From this link it says This API is provided by the DOM standard, and that's the entire API. It's deliberately generic so it can be used by other web standards and JavaScript libraries. I assume every browser has its own implementation. However, it…
yokus
  • 145
  • 2
  • 10
2
votes
0 answers

How to know Client abort Http Request in Nodejs (Nestjs)

So I use Nestjs with Observable to serve SSE. Client will call SSE API and wait for Server to send data. But Client also can cancel it. The problem is I don't know how I can know when Client abort the request so I can stop querying data in…
2
votes
0 answers

How to catch the cancellation error on an Axios request? (Custom Hook)

I'm building a custom hook for fetching data with Axios. When the request is cancelled before the response is received, you will get a cancellation error that couldn't be fetched within the try/catch block. I am able to catch it right after the…
Elwyn
  • 21
  • 4
2
votes
0 answers

use serviceworker to cancel fetch request

I have a ServiceWorker that intercepts Fetch Requests. Sometimes, the fetch request is doomed to fail, so the ServiceWorker should cancel it before it even hits the network. My code looks like: async function onFetch(event) { const { request } =…
Jakob Jingleheimer
  • 30,952
  • 27
  • 76
  • 126
2
votes
0 answers

JS AbortController - check abort signal on the server Side

I know that in javascript, fetch API's AbortController allows us to cancel HTTP requests from the client side. const abortController = new AbortController(); let httpResponse: FetchResponse; try { httpResponse = await fetch(endpointUrl, { …
Josh
  • 189
  • 1
  • 16
2
votes
0 answers

Testing AbortController Fails when it should pass

I am running into an issue with testing an abortController in a fetch in a react component. Here is my useEffect for the fetch: useEffect(() => { const abortController = new AbortController(); const url = 'string' fetch(url,…
2
votes
2 answers

What is the Typescript type for AbortController?

I can't find any reference about how to define the type for AbortController. I am using it in a React component like so: const abortController = useRef(); const doRequest = () => { abortController.current = new…
JoeTidee
  • 24,754
  • 25
  • 104
  • 149
1
vote
1 answer

Expo React native crashing on IOS after AbortController abort call

I am using expo react native fech request: const controller = new AbortController(); const { signal } = controller; fetch('xxxxxxxxx/system/sleep3000ms', { signal }) …
lacaci3709
  • 43
  • 1
  • 3
1
vote
0 answers

React hooks and Axios - cancel request ( AbortController ) is not triggered in the expected order

I have a problem that I can't seem to figure out why is happening. I created a custom hook that makes an API call to the BE every time a "filter" or "page" is changed. If the user changes some filter before the response is received, I successfully…
Mihai Stan
  • 11
  • 2
1
vote
0 answers

AbortController: how to stop instead of abort a Node.js stream?

My application has two buttons: start (to consume a stream from the server) and stop (to close the connection using AbortController). Here are my listeners: let abortController = new AbortController(); start.addEventListener('click', async () => { …
1
vote
1 answer

How to reject child Promise using AbortController

I just learned about how to reject a Promise by using the AbortController API. It's working fine but when the promise to reject as a "child Promise", this one will still continue running even if the parent Promise is rejected. Is there a way, when…
johannchopin
  • 13,720
  • 10
  • 55
  • 101
1
vote
1 answer

Why is Abort Controller not stopping my get request and why is useEffect running 3 times?

I am still new to React Js and am learning. So please bear me with me if this is a foolish question. I was trying to fetch data using get request. The problem was every time useEffect was running two times on refresh page. I researched and found…
1
2 3