Skip to content

"UnhandledPromiseRejectionWarning" if middleware throws exception (Version 1.0.0) #31

@nschmit

Description

@nschmit

When my authentication middleware is throwing an exception (see code below), an 'UnhandledPromiseRejectionWarning" is issued. The exception is not propagated further, which causes problems in my program.
This problem did not exist in the previous version 0.5.0.

export function requiresAuth(req, res, next) {
  if (req.session && req.session.user && req.session.user.id) {
    return next();
  } else {
    throw new NoValidSessionError('requiresAuth');
  }
}
requiresAuth.unless = require('express-unless');

Possible fix in index.js:

    try {
      middleware(req, res, next);
    } catch(err) {next(err)}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions