5.10. Firing an error event

To fire an error event at a request, run these steps:

  1. Let event be the result of creating an event using [Event](https://dom.spec.whatwg.org/#event).

  2. Set event’s [type](https://dom.spec.whatwg.org/#dom-event-type) attribute to “error“.

  3. Set event’s [bubbles](https://dom.spec.whatwg.org/#dom-event-bubbles) and [cancelable](https://dom.spec.whatwg.org/#dom-event-cancelable) attributes to true.

  4. Let transaction be request’s transaction.

  5. Let legacyOutputDidListenersThrowFlag be initially false.

  6. If transaction’s state is inactive, then set transaction’s state to active.

  7. Dispatch event at request with legacyOutputDidListenersThrowFlag.

  8. If transaction’s state is active, then:

    1. Set transaction’s state to inactive.

    2. If legacyOutputDidListenersThrowFlag is true, then run abort a transaction with transaction and a newly created[AbortError](https://heycam.github.io/webidl/#aborterror)[DOMException](https://heycam.github.io/webidl/#idl-DOMException) and terminate these steps. This is done even if event’s canceled flag is false.

      This means that if an error event is fired and any of the event handlers throw an exception, transaction’s [error](#dom-idbtransaction-error) property is set to an [AbortError](https://heycam.github.io/webidl/#aborterror) rather than request’s error, even if [preventDefault()](https://dom.spec.whatwg.org/#dom-event-preventdefault) is never called.

    3. If event’s canceled flag is false, then run abort a transaction using transaction and request‘s error, and terminate these steps.

    4. If transaction’s request list is empty, then run commit a transaction with transaction.