Extending a middy middleware function in nodejs

0 votes

I'd like to enhance the httpErrorhandler middleware and create a wrapper around it in my nodejs lambda code.

Currently, I have something similar to this.

module.exports.handler=middy(handle).use(httpErrorHandler(LoggingFactory.getLogger().log))

I'd like to make a customHttpErrorHandler that acts as a wrapper around httpErrorHandler.

module.exports.handler=middy(handle).use(customHttpErrorHandler(LoggingFactory.getLogger().log))

Is that even possible? What should I provide in customHttpErrorHandler? There isn't any new functionality that needs to be added. The control should be passed to the normal httpErrorHandler via this new customHandler.

Below is an example of a customHttpErrorHandler (pseudo code).

connectHttpErrorHandler = (logger) => httpErrorHandler(logger)
May 30 in Node-js by Neha
• 8,560 points
25 views

1 answer to this question.

0 votes

Your pseudocode comes close to being correct. httpErrorHandler takes an options object in Middy >=2.0.0. Documentation can be found at https://github.com/middyjs/middy/tree/main/packages/http-error-handler.

const connectHttpErrorHandler = (logger) => httpErrorHandler({logger})

const logger = LoggingFactory.getLogger().log

module.exports.handler = middy(handler)
  .use(customHttpErrorHandler(logger))
answered May 30 by Vaani
• 6,820 points

Related Questions In Node-js

0 votes
2 answers

Error:'TypeError: is not a function' in Node.js

You are exporting module.exports.redir = redir; That means that ...READ MORE

answered Oct 21, 2020 in Node-js by anonymous
• 140 points
8,743 views
0 votes
1 answer

How to provide a mysql database connection in single file in nodejs?

Hello @kartik, You could create a db wrapper ...READ MORE

answered Oct 15, 2020 in Node-js by Niroj
• 82,720 points
4,011 views
0 votes
1 answer

How to split and modify a string in NodeJS?

Hello @kartik, Use split and map function: var str = "123, 124, 234,252"; var ...READ MORE

answered Oct 16, 2020 in Node-js by Niroj
• 82,720 points
361 views
0 votes
1 answer

How to check if a collection exists in Mongodb native nodejs driver?

Hello @kartik, The collectionNames method of the native driver's Db object accepts ...READ MORE

answered Nov 27, 2020 in Node-js by Niroj
• 82,720 points
9,240 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
962 views
0 votes
1 answer
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,440 points
622 views
0 votes
1 answer

Installing angularjs with NPM and NODEJS brings an error in ubuntu 16.04

Rename your angular folder to angular-test or ...READ MORE

answered May 30 in Node-js by Vaani
• 6,820 points
13 views
0 votes
1 answer

nodejs (twit) how do you follow a users LIVE twitter stream?

In the following argument, you must use ...READ MORE

answered May 30 in Node-js by Vaani
• 6,820 points
10 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP