Skip to content
Discussion options

You must be logged in to vote

@KATT I have a couple more use cases for koa-style middleware, they simplest example being query time logging:

.middleware(async ({ ctx, path, next }) => {
  const start = Date.now()
  await next()
  const end = Date.now()
  console.log({path, ctx, took: end - start})
})

We also have some utils using async_hooks which would let us put things in AsyncLocalStorage and get them in the resolver this way. I don't think this is possible with the beforewares, but curious if you have any suggestions.

There are other things that can be done like wrapping await next() in a try/catch and doing error handling without needing special handlers.

Replies: 7 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@KATT
Comment options

KATT Jul 24, 2021
Maintainer

@KATT
Comment options

KATT Jul 24, 2021
Maintainer

Answer selected by KATT
Comment options

You must be logged in to vote
2 replies
@KATT
Comment options

KATT Mar 21, 2023
Maintainer

@octet-stream
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
4 participants
Converted from issue

This discussion was converted from issue #564 on June 22, 2021 14:14.