From 8f3f5ea0ed43fa98e8742bb831a3072cbff31cc9 Mon Sep 17 00:00:00 2001 From: jackluson Date: Sun, 24 Nov 2024 22:16:31 +0800 Subject: [PATCH] handle NamespaceIdError specially --- packages/shared/lib/cloudflare/enum.ts | 1 + packages/shared/lib/utils/index.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/shared/lib/cloudflare/enum.ts b/packages/shared/lib/cloudflare/enum.ts index 114f8c0..e723b9d 100644 --- a/packages/shared/lib/cloudflare/enum.ts +++ b/packages/shared/lib/cloudflare/enum.ts @@ -1,4 +1,5 @@ export enum ErrorCode { NotFoundRoute = 7003, AuthenicationError = 10000, + NamespaceIdError = 10011, } diff --git a/packages/shared/lib/utils/index.ts b/packages/shared/lib/utils/index.ts index 180e18d..b5e487b 100644 --- a/packages/shared/lib/utils/index.ts +++ b/packages/shared/lib/utils/index.ts @@ -22,11 +22,15 @@ export function checkCloudflareResponse( if ((res as WriteResponse)?.success) { callback({ isOk: true, msg: `${scene} success` }); } else { - const isAccountError = res?.errors?.length && res.errors[0].code === ErrorCode.NotFoundRoute; + const cloudFlareErrors = [ErrorCode.NotFoundRoute, ErrorCode.NamespaceIdError, ErrorCode.AuthenicationError]; + const isAccountError = res?.errors?.length && cloudFlareErrors.includes(res.errors[0].code); if (isAccountError) { callback({ isOk: false, - msg: 'cloudflare account info is incorrect.', + msg: + res.errors[0].code === ErrorCode.NamespaceIdError + ? 'cloudflare namespace Id info is incorrect.' + : 'cloudflare account info is incorrect.', code: MessageErrorCode.CloudflareNotFoundRoute, result: res, });