From 38be6edec3ef45d278e05d56f75d9a57fc5e0596 Mon Sep 17 00:00:00 2001 From: Nawaz Dhandala Date: Fri, 15 Aug 2025 16:29:41 +0100 Subject: [PATCH] feat: Improve DNS error handling with user-friendly messages and enhance tests for TXT and CNAME record verification --- Common/Server/Types/Domain.ts | 46 +++++++++++++------ Common/Tests/Server/Types/Domain.test.ts | 14 +++--- Docs/DevPromps/LintPrompt.md | 1 + .../{TerraformBuild.md => TerraformPrompt.md} | 0 4 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 Docs/DevPromps/LintPrompt.md rename Docs/DevPromps/{TerraformBuild.md => TerraformPrompt.md} (100%) diff --git a/Common/Server/Types/Domain.ts b/Common/Server/Types/Domain.ts index f542c15aec..3f1c6cff72 100644 --- a/Common/Server/Types/Domain.ts +++ b/Common/Server/Types/Domain.ts @@ -17,9 +17,12 @@ export default class Domain extends DomainCommon { logger.debug( `DNS CNAME lookup failed for domain ${data.domain}: ${err.message}`, ); - + // Handle specific DNS error types with user-friendly messages - if (err.message.includes("ENODATA") || err.message.includes("queryCname ENODATA")) { + if ( + err.message.includes("ENODATA") || + err.message.includes("queryCname ENODATA") + ) { reject( new BadDataException( `No CNAME records found for domain "${data.domain}". Please ensure you have added the CNAME record and wait for DNS propagation (up to 72 hours).`, @@ -27,8 +30,11 @@ export default class Domain extends DomainCommon { ); return; } - - if (err.message.includes("ENOTFOUND") || err.message.includes("queryCname ENOTFOUND")) { + + if ( + err.message.includes("ENOTFOUND") || + err.message.includes("queryCname ENOTFOUND") + ) { reject( new BadDataException( `Domain "${data.domain}" not found. Please check if the domain is correct and accessible.`, @@ -36,8 +42,11 @@ export default class Domain extends DomainCommon { ); return; } - - if (err.message.includes("ETIMEDOUT") || err.message.includes("queryCname ETIMEDOUT")) { + + if ( + err.message.includes("ETIMEDOUT") || + err.message.includes("queryCname ETIMEDOUT") + ) { reject( new BadDataException( `DNS lookup timeout for domain "${data.domain}". Please try again later.`, @@ -45,7 +54,7 @@ export default class Domain extends DomainCommon { ); return; } - + // Generic DNS error fallback reject( new BadDataException( @@ -84,32 +93,41 @@ export default class Domain extends DomainCommon { logger.debug( `DNS TXT lookup failed for domain ${domain.toString()}: ${err.message}`, ); - + // Handle specific DNS error types with user-friendly messages - if (err.message.includes("ENODATA") || err.message.includes("queryTxt ENODATA")) { + if ( + err.message.includes("ENODATA") || + err.message.includes("queryTxt ENODATA") + ) { return reject( new BadDataException( `No TXT records found for domain "${domain.toString()}". Please ensure you have added the TXT record and wait for DNS propagation (up to 72 hours).`, ), ); } - - if (err.message.includes("ENOTFOUND") || err.message.includes("queryTxt ENOTFOUND")) { + + if ( + err.message.includes("ENOTFOUND") || + err.message.includes("queryTxt ENOTFOUND") + ) { return reject( new BadDataException( `Domain "${domain.toString()}" not found. Please check if the domain is correct and accessible.`, ), ); } - - if (err.message.includes("ETIMEDOUT") || err.message.includes("queryTxt ETIMEDOUT")) { + + if ( + err.message.includes("ETIMEDOUT") || + err.message.includes("queryTxt ETIMEDOUT") + ) { return reject( new BadDataException( `DNS lookup timeout for domain "${domain.toString()}". Please try again later.`, ), ); } - + // Generic DNS error fallback return reject( new BadDataException( diff --git a/Common/Tests/Server/Types/Domain.test.ts b/Common/Tests/Server/Types/Domain.test.ts index 0300fb5813..8dae442d51 100644 --- a/Common/Tests/Server/Types/Domain.test.ts +++ b/Common/Tests/Server/Types/Domain.test.ts @@ -10,7 +10,7 @@ describe("Domain TXT Record Verification", () => { const verificationText = "test-verification-text"; await expect( - Domain.verifyTxtRecord(domain, verificationText) + Domain.verifyTxtRecord(domain, verificationText), ).rejects.toThrow(BadDataException); try { @@ -18,7 +18,9 @@ describe("Domain TXT Record Verification", () => { } catch (error) { expect(error).toBeInstanceOf(BadDataException); if (error instanceof BadDataException) { - expect(error.message).toContain("Domain \"nonexistentsubdomain-test.google.com\" not found. Please check if the domain is correct and accessible."); + expect(error.message).toContain( + 'Domain "nonexistentsubdomain-test.google.com" not found. Please check if the domain is correct and accessible.', + ); expect(error.message).toContain(domain); } } @@ -30,7 +32,7 @@ describe("Domain TXT Record Verification", () => { const verificationText = "test-verification-text"; await expect( - Domain.verifyTxtRecord(domain, verificationText) + Domain.verifyTxtRecord(domain, verificationText), ).rejects.toThrow(BadDataException); try { @@ -55,9 +57,9 @@ describe("Domain CNAME Record Verification", () => { // Testing with a domain that exists but has no CNAME records (e.g., A record only domain) const domain = "google.com"; // This is an A record, not CNAME - await expect( - Domain.getCnameRecords({ domain }) - ).rejects.toThrow(BadDataException); + await expect(Domain.getCnameRecords({ domain })).rejects.toThrow( + BadDataException, + ); try { await Domain.getCnameRecords({ domain }); diff --git a/Docs/DevPromps/LintPrompt.md b/Docs/DevPromps/LintPrompt.md new file mode 100644 index 0000000000..387786e358 --- /dev/null +++ b/Docs/DevPromps/LintPrompt.md @@ -0,0 +1 @@ +Please run "npm run fix" in the root of the project and fix all the issues that are reported by the linter. Please continue until all the issues are fixed. Please do not add "any" types or disable any rules. Please go ahead without asking for any confirmation. \ No newline at end of file diff --git a/Docs/DevPromps/TerraformBuild.md b/Docs/DevPromps/TerraformPrompt.md similarity index 100% rename from Docs/DevPromps/TerraformBuild.md rename to Docs/DevPromps/TerraformPrompt.md