Fire `request`-event on every request
- Dominant language
- JavaScript
- Stars
- 14.8k
- Forks
- 1.4k
- Avg merge
- 22d 3h
- Merged PRs (30d)
- 1
Description
#### Support plan
* *is this issue currently blocking your project?* (yes/no): no
* *is this issue affecting a production system?* (yes/no): yes
#### Context
* *node version*: 14.7.6
* *module version*: All Versions >=18.0.0
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): standalone
* *any other relevant information*: -
#### What problem are you trying to solve?
I was wondering why the `request`-event only fires in error-cases. [Before 18.0.0 the `request`-event always had the `error`-tag set](https://github.com/hapijs/hapi/issues/3898), which apparently resulted in the `request`-event being triggered at every request (which actually sounds like the correct behaviour to me). [This comment in the same issue](https://github.com/hapijs/hapi/issues/3898#issuecomment-454236132) also states that the request-event is supposed to be only fired in error-cases (which indeed is true since 18.0.0 and can be reproduced fairly easy with a failing request).
This behaviour, however, doesn't make sense to me at all due to the name of the event being `request`. By looking at the data the event-handler receives (e.g. the `channel`), it would be easy to determine whether the request resulted in an error or not and also leads to the assumption that this is the reason for the data being present.
[The documentation](https://hapi.dev/api?v=20.2.1#-request-event) also is not very clear about this behaviour, as it just states:
> The 'request' event type emits internal request events generated by the framework as well as application events logged with [request.log()](https://hapi.dev/api?v=20.2.1#request.log()).
There is no hint about this event only being triggered in error-cases.
I'd suggest to either:
- rename the current `request`-event to `error` and create a new `request`-event that fires on every request or
- just fire the current `request`-event on every request or
- add some clear information about this behaviour to the documentation of the `request`-event
I spent the whole day yesterday to investigate why a custom plugin, which reacts on the request-event, wasn't working anymore as expected, some clear documentation would have probably reduced the time spent to an hour tops or so ;)
Contributor guide
Assessment
This issue has not been assessed yet.