I'm learning Elysia by writing a simple log hook (hooks are like middleware in Elysia). I'm looking for a way to print the log by only using one hook.
I've read through the Essential section of the docs here, and through some other loggers like elysia-logging, and can't find an answer.
Right now, in order to print a log after a successful response or a request error, I need to use both onResponse and onError life cycle hooks. Something like:
import { Elysia } from 'elysia'
new Elysia()
.onResponse(() => console.log('can this be done with one hook?'))
.onError(() => console.log('can this be done with one hook?'))
.get('/', () => 'example with two hooks')
.listen(3000)
And I'm looking for something more like:
import { Elysia } from 'elysia'
new Elysia()
.onAllRepliesAtTheEnd(() => console.log('can this be done with one hook?'))
.get('/', () => 'example with two hooks')
.listen(3000)
Is there a life cycle hook that works like the above example that uses the non-existent onAllRepliesAtTheEnd hook? Or do I need to write a separate console.log, one for onResponse and one for onError?
Is there a life cycle that happens after either a response or an error happens? Or is there no life cycle connection between response and error after they happen?