I understand that if you have a function you can get the name with the property name
and if it is a class you can get the name prototype.name
but as I get the name of a promise, the problem is as follows
I have several functions type async
and when they have an error I skip the event
unhandledRejection
which returns me two parameters error
and promise
now what I want is to print the name of the function that returns the error
an example of my code
app.get('/', async function index (req, res, next) {
throw new Error('hay ja jay, un error compadre')
})
process.on('unhandledRejection', (err, p) => {
console.error('a ocurrido en la funcion ${p} el siguiente error: ', err)
})
lv5 summary:
how do I get the name of p
edit:
the code that comes from an api json made in express and I have different routes each controller of a route uses a function callback
that can be a normal function anonymous, a promise or a function async
, this last type of function I use it for reading reasons in the code
and it actually behaves as if it were a promise.
Now it is good practice for debugging in nodejs to have the functions named so I have the function as follows
async function index (req, res, next) {
}
these functions are captured errors with try
and catch
as any and being a
callback
of an express endpoint receives the parameters req
, res
and next
the normal thing is to pass the error to next
for it to handle the express handler error
but what I want is to make the error handler of the own node unhandledRejection
and see if I can register with the name of the promise of this case bone 'index'