Skip to content
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

Error handler is always executed #22

Open
henryjw opened this issue Dec 31, 2018 · 4 comments
Open

Error handler is always executed #22

henryjw opened this issue Dec 31, 2018 · 4 comments

Comments

@henryjw
Copy link

henryjw commented Dec 31, 2018

Does this library support adding error-handling middleware via router.use()? I'm trying to create a generic handler for a router, but it's being executed before the route handlers.

Example:

app.get('/api/data', function dataHandler(req, res, next) {
    // Process request
});


// Always executes before `dataHandler()`. 
app.use(function errorHandler(err, req, res, next) {
    // Handle error
});
@ukayani
Copy link
Owner

ukayani commented Dec 31, 2018

Hi @henryjw , handlers registered via the .use method will always run before route handlers. The router interface just proxies the behaviour of the restify server. The .use method on the server is meant to add handlers which execute before route handlers.
From what I understand, you wish to add a post route handler?

@henryjw
Copy link
Author

henryjw commented Dec 31, 2018

Thanks for the quick response @ukayani. Yup, a post route handler is basically what I'm looking for. Is there a way to implement that with this library?

@ukayani
Copy link
Owner

ukayani commented Jan 3, 2019

At the moment there is no such feature. It should not be too hard to add it though. I'll try to take a look over the weekend.

@henryjw
Copy link
Author

henryjw commented Jan 7, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants