skonves / express-http-context

Get and set request-scoped context anywhere
MIT License
299 stars 26 forks source link

Context not available in unhandledRejection handler #38

Closed schuma7 closed 5 years ago

schuma7 commented 5 years ago

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?

rohitsud commented 5 years ago

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.