Skip to content

How could I use the request or context in formatError()? #134

Answered by enisdenjo
jleeothon asked this question in Q&A
Discussion options

You must be logged in to vote

At the moment, this syntax is not supported. This could be a good feature to add though.

However, you can achieve the same thing by using the createHandle IIFE style:

- const middleware = createHandler({
+ const middleware = (request, response, params) => createHandler({
  formatError(error) {
    // Have access to error and request or context
  }
- });
+ })(request, response, params);

app.use('/some/path', middleware);

Since the creation of the handler is a cheap operation, this should not cause any issues performance-wise.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jleeothon
Comment options

Answer selected by enisdenjo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants