From 02437b0bfbde2bdff81e912eed5fd073f7b7c1ab Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Tue, 24 Oct 2023 09:59:16 +0200 Subject: [PATCH] add validator functions for backend-api types --- .../shared/resources/apiTypeValidators.function.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/Umbraco.Web.UI.Client/src/shared/resources/apiTypeValidators.function.ts diff --git a/src/Umbraco.Web.UI.Client/src/shared/resources/apiTypeValidators.function.ts b/src/Umbraco.Web.UI.Client/src/shared/resources/apiTypeValidators.function.ts new file mode 100644 index 0000000000..091120886e --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/shared/resources/apiTypeValidators.function.ts @@ -0,0 +1,13 @@ +import type { ApiError, CancelError, CancelablePromise } from '@umbraco-cms/backoffice/backend-api'; + +export function isApiError(error: unknown): error is ApiError { + return (error as ApiError).name === 'ApiError'; +} + +export function isCancelError(error: unknown): error is CancelError { + return (error as CancelError).name === 'CancelError'; +} + +export function isCancelablePromise(promise: unknown): promise is CancelablePromise { + return (promise as CancelablePromise).cancel !== undefined; +}