AbortSignal: reason property
The reason property is the reason for aborting.
Value
Any value.
- Read-only; assigning to it throws
TypeError. undefinedbefore aborting.- When a reason was given with
controller.abort(reason)orAbortSignal.abort(reason), it is that value. - When no reason was given, it is an
Errorwhosenameis'AbortError'and whosemessageisThe operation was aborted. - When
AbortSignal.timeout()expires, it is anErrorwhosenameis'TimeoutError'and whosemessageisThe operation timed out. - On aborting, the
abortevent fires, and it doesn't change afterward.
Examples
js
const controller = new AbortController();
controller.abort();
const reason = controller.signal.reason;
console.log(reason instanceof Error ? reason.name : reason);Result: Prints AbortError.
Differences from the web
The default reason is an Error, not a DOMException.