| title | PromiseRejectionEvent |
|---|---|
| slug | Web/API/PromiseRejectionEvent |
| page-type | web-api-interface |
| browser-compat | api.PromiseRejectionEvent |
{{APIRef("HTML DOM")}}{{AvailableInWorkers}}
The PromiseRejectionEvent interface represents events which are sent to the global script context when JavaScript {{jsxref("Promise")}}s are rejected. These events are particularly useful for telemetry and debugging purposes.
For details, see Promise rejection events.
{{InheritanceDiagram}}
- {{domxref("PromiseRejectionEvent.PromiseRejectionEvent", "PromiseRejectionEvent()")}}
- : Creates a
PromiseRejectionEventevent, given the type of event (unhandledrejectionorrejectionhandled) and other details.
- : Creates a
Also inherits properties from its parent {{domxref("Event")}}.
- {{domxref("PromiseRejectionEvent.promise")}} {{ReadOnlyInline}}
- : The JavaScript {{jsxref("Promise")}} that was rejected.
- {{domxref("PromiseRejectionEvent.reason")}} {{ReadOnlyInline}}
- : A value or {{jsxref("Object")}} indicating why the promise was rejected, as passed to {{jsxref("Promise.reject()")}}.
This interface has no unique methods; inherits methods from its parent {{domxref("Event")}}.
- {{domxref("Window/rejectionhandled_event", "rejectionhandled")}}
- : Fired when a JavaScript {{jsxref("Promise")}} is rejected, and after the rejection is handled by the promise's rejection handling code.
- {{domxref("Window/unhandledrejection_event", "unhandledrejection")}}
- : Fired when a JavaScript {{jsxref("Promise")}} is rejected but there is no rejection handler to deal with the rejection.
This simple example catches unhandled promise rejections and logs them for debugging purposes.
window.onunhandledrejection = (e) => {
console.log(e.reason);
};{{Specifications}}
{{Compat}}
- Using promises
- {{jsxref("Promise")}}
- {{domxref("Window/rejectionhandled_event", "rejectionhandled")}}
- {{domxref("Window/unhandledrejection_event", "unhandledrejection")}}