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.request
eventEmitted immediately after a request is instantiated.
cancelError
eventEmitted when the response promise is rejected with an error whose
name
iscancel
. The error is passed as the second argument.timeoutError
eventEmitted when the response promise is rejected with an error whose
name
istimeout
. The error is passed as the second argument.internalError
eventEmitted when the response promise is rejected with any other error. The error is passed as the second argument.
response
eventEmitted just before the headers are written to the outgoing message.
responseFinish
eventEmitted when the outgoing message emits its
finish
event.responseCancel
eventEmitted when the outgoing message emits its
close
event while the response is being written.streamingError
eventEmitted if errors occurred when piping the response stream. The error is passed as the second argument.
streamObservationFailed
eventEmitted when listening for
error
events from the response stream throws an error. The error is passed as the second argument.