diff --git a/src/util/createValidation.ts b/src/util/createValidation.ts index dc21e48c..4d946bab 100644 --- a/src/util/createValidation.ts +++ b/src/util/createValidation.ts @@ -137,27 +137,23 @@ export default function createValidation(config: { const shouldSkip = skipAbsent && isAbsent(value); - if (!options.sync) { - try { - Promise.resolve(!shouldSkip ? test.call(ctx, value, ctx) : true).then( - handleResult, - handleError, - ); - } catch (err: any) { - handleError(err); - } - - return; + if (shouldSkip) { + return handleResult(true); } let result: ReturnType; try { - result = !shouldSkip ? test.call(ctx, value, ctx) : true; - + result = test.call(ctx, value, ctx); if (typeof (result as any)?.then === 'function') { - throw new Error( - `Validation test of type: "${ctx.type}" returned a Promise during a synchronous validate. ` + - `This test will finish after the validate call has returned`, + if (options.sync) { + throw new Error( + `Validation test of type: "${ctx.type}" returned a Promise during a synchronous validate. ` + + `This test will finish after the validate call has returned`, + ); + } + return Promise.resolve(result).then( + handleResult, + handleError, ); } } catch (err: any) {