Merged
Conversation
35389f8 to
d417ff7
Compare
Member
Author
|
What about adding |
Member
|
This makes a lot of sense, thank you! That the app.service('users').hooks({
create: [
async (context, next) => {
const finally = async () => {
// Finally code here
}
try {
await next();
await finally();
} catch (error) {
await finally();
throw error;
}
}
]
}A convenience wrapper may also make this shorter. |
Member
Author
|
Cool about koa style, prefer it too. By the way your example snippet has the same problem as this pull request solves for current system: if your Instead of: try {
await next();
await finally();
} catch (error) {
await finally();
throw error;
}It should be: try {
await next();
} finally {
await finally();
} |
Member
|
Ah, totally. That's totally it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes two errors:
finallyhooks can possibly run twice for same method call if one of them throws. Also afinallyhook if throws activateserrorhooks, this is in conflict with this comment and alsoPromise.finallyandtry/catch/finallyconvention. Because currently it is like this (1, 2):errorhook can get a context which is not up to date, if anybeforehook returns new context object and a service method throws, because errors (1, 2) thrown in a method invocation do no havehookproperty set (which should contain a last valid hook context), that's whyerrorhooks end up using an initial hook object.Added fixes and tests for such cases. Also small clean up changes for readability and performance.
A question for future: What are use cases for allowing returning new context object from hook functions where modifying context in place is not as convenient?