Update Lifecyclecallbacks.md with error handling #853
Conversation
Clear advice about making sure thrown errors or rejections make it back to the callback and why.
LGTM! |
Thanks @ashleysimons ! |
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.
Thanks for taking the time to write this up! A few asks before merging
|
||
It's important to realize that Sails will not catch thrown errors in your callbacks. If there is any chance the code you are executing will throw an `Error`, please wrap it in a `try catch` and pass the error to the callback. |
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.
Can we clarify "in lifecycle callbacks" here?
@@ -67,6 +67,33 @@ module.exports = { | |||
}; | |||
``` | |||
|
|||
### Error handling ### |
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.
Can we trim the extra set of ###
- it could confuse our doctemplater tool
} | ||
``` | ||
|
||
If you are using promises, please define a `catch` and pass the error to the callback. A promise will swallow the error. |
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.
Can we replace this with an async/await example?
@ashleysimons Reverted in #936 but would love to remerge if you wouldn't mind making the changes above Also, would you make the changes against the 1.0 branch? Thanks again! |
Clear advice about making sure thrown errors or rejections make it back to the callback and why.