Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new AbortController instance.
Node.js
const controller = new [1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using AbortSignal instead of AbortController.
Using Promise which is unrelated here.
✗ Incorrect
The AbortController is used to create a controller that can abort asynchronous tasks.
2fill in blank
mediumComplete the code to get the signal from the AbortController.
Node.js
const signal = controller.[1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'abort' which is a method, not a property.
Using 'cancel' which does not exist.
✗ Incorrect
The signal property of the controller provides the signal to pass to async tasks for cancellation.
3fill in blank
hardFix the error in the code to abort the controller.
Node.js
controller.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cancel' which is not a method of AbortController.
Using 'stop' or 'end' which do not exist.
✗ Incorrect
The abort() method triggers the cancellation signal.
4fill in blank
hardFill both blanks to create a fetch request that can be aborted.
Node.js
fetch(url, { signal: [1] }).then(response => response.[2]()); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the controller instead of its signal.
Using 'text' instead of 'json' when expecting JSON data.
✗ Incorrect
The signal property is passed to fetch for cancellation, and json() parses the response body.
5fill in blank
hardFill all three blanks to handle abort error in a fetch request.
Node.js
try { await fetch(url, { signal: [1] }); } catch (error) { if (error.[2] === '[3]') { console.log('Fetch aborted'); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking error.message instead of error.name.
Passing controller instead of signal.
✗ Incorrect
The signal is passed to fetch. The error's name property is checked for 'AbortError' to detect cancellation.