doc/Events.md
Events are emitted from the stack when new requests are made, errors occur, or responses are written.
The first argument for every emitted event is a state object, with the following properties:
incomingMessage
outgoingMessage
request
response
streaming
Emitted immediately after a request is instantiated.
cancelError
Emitted when the response promise is rejected with an error whose name is cancel. The error is passed as the second argument.
name
cancel
timeoutError
Emitted when the response promise is rejected with an error whose name is timeout. The error is passed as the second argument.
timeout
internalError
Emitted when the response promise is rejected with any other error. The error is passed as the second argument.
Emitted just before the headers are written to the outgoing message.
responseFinish
Emitted when the outgoing message emits its finish event.
finish
responseCancel
Emitted when the outgoing message emits its close event while the response is being written.
close
streamingError
Emitted if errors occurred when piping the response stream. The error is passed as the second argument.
streamObservationFailed
Emitted when listening for error events from the response stream throws an error. The error is passed as the second argument.
error
Events
Events are emitted from the stack when new requests are made, errors occur, or responses are written.
State object
The first argument for every emitted event is a state object, with the following properties:
incomingMessage: The incoming message.outgoingMessage: The outgoing message.request: The request instantiated for the stack.response: The final response that's supposed to be written to the outgoing message.streaming: Whether the response is being streamed to the outgoing message.requesteventEmitted immediately after a request is instantiated.
cancelErroreventEmitted when the response promise is rejected with an error whose
nameiscancel. The error is passed as the second argument.timeoutErroreventEmitted when the response promise is rejected with an error whose
nameistimeout. The error is passed as the second argument.internalErroreventEmitted when the response promise is rejected with any other error. The error is passed as the second argument.
responseeventEmitted just before the headers are written to the outgoing message.
responseFinisheventEmitted when the outgoing message emits its
finishevent.responseCanceleventEmitted when the outgoing message emits its
closeevent while the response is being written.streamingErroreventEmitted if errors occurred when piping the response stream. The error is passed as the second argument.
streamObservationFailedeventEmitted when listening for
errorevents from the response stream throws an error. The error is passed as the second argument.