parse-community / parse-community/parse-server
Cloud validation: Custom error handling instead of throwing errors
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 21.4k
- Forks
- 4.8k
- Avg merge
- 7h 45m
- Merged PRs (30d)
- 11
Description
New Feature / Enhancement Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
Current Limitation
While cloud code validation if a condition doesn't met an error is thrown.
Feature / Enhancement Description
Add a possibility to handle errors of the cloud code validation on our own by passing an afterValidation function. If the function returns anything (or throws), the cloud function won't get executed. The returned data of this function will also returned to the client.
Parse.Cloud.define("coolCloudCode", async req => {
}, {
requireUser: true,
requireAnyUserRoles: [
"supporter",
],
afterValidation: (error) => {
if (error) {
return {
error: {
message: "validation failed"
}
}
}
}
});
Example Use Case
We are returning JSON objects in every of our cloud functions which contain an success or an error object instead of throwing if something fails. We have chosen this style to make sure that errors are only thrown if there are network issues.
Alternatives / Workarounds
Our current solution:
Parse.Cloud.define("generatePromotionCodes", async req => {
if (
!req.master
&&
(await checkUserRole({
user: req.user,
roleNames: [
"supporter",
],
}))
.error
) {
return {
error: {
message: "No master key or not supported user."
}
}
}
});
Would be much easier if we could use the cloud code validation.
3rd Party References
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Parse.Cloud.define and the existing cloud code validation flow. Clarify how an afterValidation callback should receive validation errors, handle returned values or thrown errors, and prevent execution. Done means the behavior is specified consistently for the client and covered by appropriate tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100