From e6e649a8f3e307c455a870397021773b0ee562d6 Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Tue, 21 Oct 2025 10:31:41 +0100 Subject: [PATCH] Simplify API error checks --- lib/analyze-action.js | 7 ++++++- lib/init-action-post.js | 7 ++++++- lib/init-action.js | 7 ++++++- lib/setup-codeql-action.js | 7 ++++++- lib/upload-lib.js | 7 ++++++- lib/upload-sarif-action.js | 7 ++++++- src/api-client.ts | 10 ++++++---- 7 files changed, 42 insertions(+), 10 deletions(-) diff --git a/lib/analyze-action.js b/lib/analyze-action.js index b309b4874..907012ba9 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -90389,7 +90389,12 @@ async function deleteActionsCache(id) { function wrapApiConfigurationError(e) { const httpError = asHTTPError(e); if (httpError !== void 0) { - if (httpError.message.includes("API rate limit exceeded") || httpError.message.includes("commit not found") || httpError.message.includes("Resource not accessible by integration") || /ref .* not found in this repository/.test(httpError.message)) { + if ([ + /API rate limit exceeded/, + /commit not found/, + /Resource not accessible by integration/, + /ref .* not found in this repository/ + ].some((pattern) => pattern.test(httpError.message))) { return new ConfigurationError(httpError.message); } if (httpError.message.includes("Bad credentials") || httpError.message.includes("Not Found")) { diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 8d6dc5f30..034cc4880 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -128620,7 +128620,12 @@ async function listActionsCaches(key, ref) { function wrapApiConfigurationError(e) { const httpError = asHTTPError(e); if (httpError !== void 0) { - if (httpError.message.includes("API rate limit exceeded") || httpError.message.includes("commit not found") || httpError.message.includes("Resource not accessible by integration") || /ref .* not found in this repository/.test(httpError.message)) { + if ([ + /API rate limit exceeded/, + /commit not found/, + /Resource not accessible by integration/, + /ref .* not found in this repository/ + ].some((pattern) => pattern.test(httpError.message))) { return new ConfigurationError(httpError.message); } if (httpError.message.includes("Bad credentials") || httpError.message.includes("Not Found")) { diff --git a/lib/init-action.js b/lib/init-action.js index 0e0a49e24..d16921d20 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -86269,7 +86269,12 @@ async function getRepositoryProperties(repositoryNwo) { function wrapApiConfigurationError(e) { const httpError = asHTTPError(e); if (httpError !== void 0) { - if (httpError.message.includes("API rate limit exceeded") || httpError.message.includes("commit not found") || httpError.message.includes("Resource not accessible by integration") || /ref .* not found in this repository/.test(httpError.message)) { + if ([ + /API rate limit exceeded/, + /commit not found/, + /Resource not accessible by integration/, + /ref .* not found in this repository/ + ].some((pattern) => pattern.test(httpError.message))) { return new ConfigurationError(httpError.message); } if (httpError.message.includes("Bad credentials") || httpError.message.includes("Not Found")) { diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index 506969cb5..5f92319ca 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -84769,7 +84769,12 @@ async function getAnalysisKey() { function wrapApiConfigurationError(e) { const httpError = asHTTPError(e); if (httpError !== void 0) { - if (httpError.message.includes("API rate limit exceeded") || httpError.message.includes("commit not found") || httpError.message.includes("Resource not accessible by integration") || /ref .* not found in this repository/.test(httpError.message)) { + if ([ + /API rate limit exceeded/, + /commit not found/, + /Resource not accessible by integration/, + /ref .* not found in this repository/ + ].some((pattern) => pattern.test(httpError.message))) { return new ConfigurationError(httpError.message); } if (httpError.message.includes("Bad credentials") || httpError.message.includes("Not Found")) { diff --git a/lib/upload-lib.js b/lib/upload-lib.js index eca7065e9..aedb14ab9 100644 --- a/lib/upload-lib.js +++ b/lib/upload-lib.js @@ -88764,7 +88764,12 @@ function computeAutomationID(analysis_key, environment) { function wrapApiConfigurationError(e) { const httpError = asHTTPError(e); if (httpError !== void 0) { - if (httpError.message.includes("API rate limit exceeded") || httpError.message.includes("commit not found") || httpError.message.includes("Resource not accessible by integration") || /ref .* not found in this repository/.test(httpError.message)) { + if ([ + /API rate limit exceeded/, + /commit not found/, + /Resource not accessible by integration/, + /ref .* not found in this repository/ + ].some((pattern) => pattern.test(httpError.message))) { return new ConfigurationError(httpError.message); } if (httpError.message.includes("Bad credentials") || httpError.message.includes("Not Found")) { diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index 01d2556c4..36ed7f67b 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -88975,7 +88975,12 @@ function computeAutomationID(analysis_key, environment) { function wrapApiConfigurationError(e) { const httpError = asHTTPError(e); if (httpError !== void 0) { - if (httpError.message.includes("API rate limit exceeded") || httpError.message.includes("commit not found") || httpError.message.includes("Resource not accessible by integration") || /ref .* not found in this repository/.test(httpError.message)) { + if ([ + /API rate limit exceeded/, + /commit not found/, + /Resource not accessible by integration/, + /ref .* not found in this repository/ + ].some((pattern) => pattern.test(httpError.message))) { return new ConfigurationError(httpError.message); } if (httpError.message.includes("Bad credentials") || httpError.message.includes("Not Found")) { diff --git a/src/api-client.ts b/src/api-client.ts index db66cd8ab..59c687b68 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -283,10 +283,12 @@ export function wrapApiConfigurationError(e: unknown) { const httpError = asHTTPError(e); if (httpError !== undefined) { if ( - httpError.message.includes("API rate limit exceeded") || - httpError.message.includes("commit not found") || - httpError.message.includes("Resource not accessible by integration") || - /ref .* not found in this repository/.test(httpError.message) + [ + /API rate limit exceeded/, + /commit not found/, + /Resource not accessible by integration/, + /ref .* not found in this repository/, + ].some((pattern) => pattern.test(httpError.message)) ) { return new ConfigurationError(httpError.message); }