Skip to content

Commit

Permalink
fix(docs): Correct documentation for validateSync and `validateWith…
Browse files Browse the repository at this point in the history
…Sync` (#9080)

Pretty confident I cleaned it up correctly, but please double check!
  • Loading branch information
BlackHawkSigma authored and jtoar committed Sep 2, 2023
1 parent ebcdeda commit 36cf2d8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions docs/docs/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ validate(input.value, 'Value', {
```
### validateWithSync()
`validateWith()` is simply given a function to execute. This function should throw with a message if there is a problem, otherwise do nothing.
`validateWithSync()` is simply given a function to execute. This function should throw with a message if there is a problem, otherwise do nothing.
```jsx
validateWithSync(() => {
Expand All @@ -636,14 +636,14 @@ validateWithSync(() => {
Either of these errors will be caught and re-thrown as a `ServiceValidationError` with your text as the `message` of the error (although technically you should always throw errors with `new Error()` like in the second example).
You could just write your own function and throw whatever you like, without using `validateWith()`. But, when accessing your Service function through GraphQL, that error would be swallowed and the user would simply see "Something went wrong" for security reasons: error messages could reveal source code or other sensitive information so most are hidden. Errors thrown by Service Validations are considered "safe" and allowed to be shown to the client.
You could just write your own function and throw whatever you like, without using `validateWithSync()`. But, when accessing your Service function through GraphQL, that error would be swallowed and the user would simply see "Something went wrong" for security reasons: error messages could reveal source code or other sensitive information so most are hidden. Errors thrown by Service Validations are considered "safe" and allowed to be shown to the client.
### validateWithSync()
### validateWith()
The same behavior as `validateWithSync()` but works with Promises.
The same behavior as `validateWithSync()` but works with Promises. Remember to `await` the validation.
```jsx
validateWithSync(async () => {
await validateWith(async () => {
if (await db.products.count() >= 100) {
throw "There can only be a maximum of 100 products in your store"
}
Expand Down

0 comments on commit 36cf2d8

Please sign in to comment.