diff options
| author | rxliuli <rxliuli@gmail.com> | 2025-11-04 05:03:50 +0800 |
|---|---|---|
| committer | rxliuli <rxliuli@gmail.com> | 2025-11-04 05:03:50 +0800 |
| commit | bce557cc2dc767628bed6aac87301a1be7c5431b (patch) | |
| tree | b51a051228d01fe3306cd7626d4a96768aadb944 /node_modules/@jet-app/app-store/tmp/src/foundation/util/validation-util.js | |
init commit
Diffstat (limited to 'node_modules/@jet-app/app-store/tmp/src/foundation/util/validation-util.js')
| -rw-r--r-- | node_modules/@jet-app/app-store/tmp/src/foundation/util/validation-util.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/node_modules/@jet-app/app-store/tmp/src/foundation/util/validation-util.js b/node_modules/@jet-app/app-store/tmp/src/foundation/util/validation-util.js new file mode 100644 index 0000000..fe9bd93 --- /dev/null +++ b/node_modules/@jet-app/app-store/tmp/src/foundation/util/validation-util.js @@ -0,0 +1,30 @@ +import { isSome } from "@jet/environment"; +import * as validation from "@jet/environment/json/validation"; +import { tryAwait } from "./promise-util"; +/** + * Creates a validation context for async operations and ensures proper cleanup. + * + * Wraps an async operation in a validation context, automatically handling + * context cleanup even when errors occur. Optionally processes errors through + * a provided error handler. + * + * @param name - The name for the validation context + * @param producer - Async function that produces the result + * @param errorHandler - Optional function to handle errors from the producer + * @returns The result of the async operation + */ +export async function withAsyncValidationContext(name, producer, errorHandler) { + validation.beginContext(name); + let result = await tryAwait(producer()); + if (!result.success && isSome(errorHandler)) { + result = await tryAwait(errorHandler(result.error)); + } + validation.endContext(); + if (!result.success) { + throw result.error; + } + else { + return result.value; + } +} +//# sourceMappingURL=validation-util.js.map
\ No newline at end of file |
