-
Notifications
You must be signed in to change notification settings - Fork 983
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
Inconsistent argument order for error event listeners #753
Comments
While it means breaking the added error event API in 2.8.5, I'm inclined to swap the order of the I've staged a5c5d7b for review. Thoughts? |
We can also put |
@pfmooney Thanks for staging a potential fix. I'd rather not buck node's convention of the last argument being the cb and swap the cb and err args. In this case since we're listening for an error event, the error object should be a first class object. Hijacking it onto either the res or req object doesn't seem like a good fit. We could change the API to one that returns a context object, and a cb like so:
But this seems like an even bigger breaking change. I'm inclined to leave the API is and just make this breaking change to the API. @vickvu my apologies for not realizing this was an issue before. |
@yunong I agree that we shouldn't be hijacking req/res to pass the err object. If we're accepting the break in API, I suggest that we pass null |
@pfmooney That's a great idea. |
I'll refactor my branch to that effect. @mcavage Care to weigh in? |
@pfmooney Actually we should probably just pass back a new error from the router. |
@yunong We can just use the |
@pfmooney +1 for passing a standard err object and just nulling it when things are good. That's what everyone would expect - this was a new feature that I doubt many people are using so now's the time to break it. |
Since the pull request at #741, error event listeners will be called with either
(request, response, cb)
or(request, response, error, cb)
.For e.g. given the following code
The code works fine if the route is not found and the server throw a ResourceNotFoundError. However, if a ResourceNotFoundError is returned by a controller
then the above listener will be triggered with
(request, response, error, callback)
(https://github.com/mcavage/node-restify/blob/master/lib/server.js#L666)The text was updated successfully, but these errors were encountered: