From 36cf2d8f08846ef2313629dd386b0c83c3eee2db Mon Sep 17 00:00:00 2001 From: Tobias Date: Wed, 30 Aug 2023 17:10:55 +0200 Subject: [PATCH] fix(docs): Correct documentation for `validateSync` and `validateWithSync` (#9080) Pretty confident I cleaned it up correctly, but please double check! --- docs/docs/services.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/docs/services.md b/docs/docs/services.md index 67fd73ae1362..3301a7719d81 100644 --- a/docs/docs/services.md +++ b/docs/docs/services.md @@ -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(() => { @@ -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" }