New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow plugins to inject error handlers in core error handling route #5925

Closed
julianlam opened this Issue Sep 12, 2017 · 1 comment

Comments

Projects
None yet
1 participant
@julianlam
Copy link
Member

julianlam commented Sep 12, 2017

Right now if errors are passed back, they are bubbled up to the NodeBB core level where we display the generic 500 error page with err.message.

Let's allow plugins to define a custom handler if necessary.

@julianlam julianlam added this to the 1.6.1 milestone Sep 12, 2017

@julianlam julianlam self-assigned this Sep 12, 2017

@julianlam

This comment has been minimized.

Copy link
Member

julianlam commented Sep 12, 2017

Plugins can add new error handlers by subscribing to the filter:error.handle hook, with a method thusly:

myPlugin.handleErrors = function (data, next) {
  data.cases['banned'] = function (err, req, res, next) {
    res.redirect('https://url.to.external.app/banned?reason=naughty%20user');
  };

  return next(null, data);
}

In the above example, on 'banned' error, we redirect the user off-site instead of showing the default NodeBB error page. If you do want to show the error page (for example, if you're just logging analytics), then just call next(); when you're done.

To invoke that error, you'd do something like:

var error = new Error();
err.code = 'banned';

callback(error);

@julianlam julianlam closed this in 9f4e92f Oct 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment