From 7bb60eeff89e425994615969d884c140a56d6433 Mon Sep 17 00:00:00 2001 From: wangsijie Date: Mon, 14 Aug 2023 10:51:06 +0800 Subject: [PATCH] fix(core): fix cloudflare hostname not found error handler (#4316) fix(core): fix cloudflare hostnme not found error handler --- packages/core/src/libraries/domain.test.ts | 10 ++++++++++ packages/core/src/libraries/domain.ts | 8 +++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/core/src/libraries/domain.test.ts b/packages/core/src/libraries/domain.test.ts index 9a8a41d24..51f03a30a 100644 --- a/packages/core/src/libraries/domain.test.ts +++ b/packages/core/src/libraries/domain.test.ts @@ -149,4 +149,14 @@ describe('deleteDomain()', () => { expect(clearCustomDomainCache).toBeCalledTimes(1); expect(deleteDomainById).toBeCalledTimes(1); }); + + it('should delete local record even if the record is not found in remote', async () => { + findDomainById.mockResolvedValueOnce(mockDomainWithCloudflareData); + deleteCustomHostname.mockRejectedValueOnce( + new RequestError({ code: 'domain.cloudflare_not_found' }) + ); + await expect(deleteDomain(mockDomain.id)).resolves.not.toThrow(); + expect(clearCustomDomainCache).toBeCalledTimes(1); + expect(deleteDomainById).toBeCalledTimes(1); + }); }); diff --git a/packages/core/src/libraries/domain.ts b/packages/core/src/libraries/domain.ts index fd5a0055b..73a244c9f 100644 --- a/packages/core/src/libraries/domain.ts +++ b/packages/core/src/libraries/domain.ts @@ -103,12 +103,10 @@ export const createDomainLibrary = (queries: Queries) => { try { await deleteCustomHostname(hostnameProviderConfig, domain.cloudflareData.id); } catch (error: unknown) { - if (error instanceof RequestError && error.code === 'domain.cloudflare_not_found') { - // Ignore not found error, since we are deleting the domain anyway - return; + // Ignore not found error, since we are deleting the domain anyway + if (!(error instanceof RequestError) || error.code !== 'domain.cloudflare_not_found') { + throw error; } - - throw error; } }