Skip to content

Commit 3350d09

Browse files
author
Jayson Ng
committed
Added Example on how to abort Hooks and functions
Added Example on how to abort Hooks and functions Source: https://github.com/parse-community/parse-server/blob/master/3.0.0.md
1 parent 5e8f64e commit 3350d09

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

_includes/cloudcode/cloud-code.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,21 @@ Parse.Cloud.beforeSave(Parse.User, async (request) => {
217217
})
218218
```
219219

220+
## Aborting hooks and functions
221+
In order to abort a beforeSave or any hook, you now need to throw an error:
222+
223+
```javascript
224+
// after with async/await
225+
Parse.Cloud.beforeSave('MyClassName', async (request) => {
226+
// valid, will result in a Parse.Error(SCRIPT_FAILED, 'Something went wrong')
227+
throw 'Something went wrong'
228+
// also valid, will fail with Parse.Error(SCRIPT_FAILED, 'Something else went wrong')
229+
throw new Error('Something else went wrong')
230+
// using a Parse.Error is also valid
231+
throw new Parse.Error(1001, 'My error')
232+
});
233+
```
234+
220235
# afterSave Triggers
221236

222237
In some cases, you may want to perform some action, such as a push, after an object has been saved. You can do this by registering a handler with the `afterSave` method. For example, suppose you want to keep track of the number of comments on a blog post. You can do that by writing a function like this:

0 commit comments

Comments
 (0)