skonves/express-http-context

Context not available in unhandledRejection handler

Closed this issue · 1 comments

I added an express middleware that creates a uuid for every incoming request so that I can easily correlate logs belonging to a single service call.

When adding this code to one of the service classes in order to generate an unhandled promise rejection:

new Promise((res, rej) => {
   rej(new Error('some rejection'));
});

it seems as if the process.on('unhandledRejection', ...) handler does not have access to the context.

Is this expected behaviour or a bug in the library?

This is expected since the event unhandledRejection is not called in the context of a promise rejection and doesn't have its context in the continuation-local-storage.