-
Notifications
You must be signed in to change notification settings - Fork 212
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
Updating library for asynchronous support through promises #171
Conversation
If @mreinstein would like to do a constructive code review here that'd be much appreciated. Removing non-promised versions to simplify the code in the medium term and #22 is what we're trying to accomplish. |
Also see #173. |
ad2a1e0
to
5ee51c7
Compare
index.js
Outdated
if (e.message) { | ||
return response.fail("Unhandled exception: " + e.message + ".", e); | ||
} else { | ||
return response.fail("Unhandled exception.", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e
often contains a string and this should be part of the .fail() call, especially if
e is an indexed message (
self.messages[e]`).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean something like response.fail("Unhandled exception: " + e, e)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly!
index.js
Outdated
}) | ||
.catch(function(e) { | ||
if (typeof self.error == "function") { | ||
self.error(e, request, response); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the default behavior should be to resolve by calling response.send()
here as the user error handler, app.error()
can still explicitly fail if desired.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments on #182 -- I can change this to return self.error
and update the documentation to say that error can be async.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should next expect the error handler to return anything in release v3. Instead a call to resolve.send() if it has not been already resolved should suffice. I submitted PR #183 to handle.
5ee51c7
to
2a839a3
Compare
@dblock this is now up-to-date with current changes and makes Anything else we need to do to proceed with this update? We can work off of a v4 branch and create an rc rather than using master if we want to spend some time with v3. |
Can you take a look at #186 and merge it if it makes sense? I think @tejashah88 is not around. Then make a 3.2.0 release (follow RELEASING) and I will merge this PR right behind it? |
What are we paying you for @tejashah88 ;) |
2a839a3
to
d21c406
Compare
This required some updates to the core code to make sure the promise chain and corresponding values are always passed appropriately
Also updated library to ignore value returned from handler as this would be considered an exception to response.send
1dea61a
to
244cad9
Compare
I'm merging this. |
This completes the change for #134. Asynchronous support is no longer backwards compatible, and the
return false
and callbacks to handlers have been removed. Now, returning Promises from handlers is required for asynchronous support.pre
andpost
now both also have asynchronous support. The API functions identically as before as long as you use the Promise chain for asynchronicity.response.send
andresponse.fail
can force immediate success or failure..post
can still recover failures. Theresponse.send
andresponse.fail
methods return promises that must be returned from inside the promise chain in order to continue it.Also closes #22