mirror of
https://github.com/github/codeql-action.git
synced 2025-12-23 07:40:10 +08:00
Handle HTTP errors with httpStatusCode property
This commit is contained in:
48
lib/upload-lib.js
generated
48
lib/upload-lib.js
generated
@@ -80921,14 +80921,14 @@ var require_tool_cache = __commonJS({
|
||||
var assert_1 = require("assert");
|
||||
var exec_1 = require_exec();
|
||||
var retry_helper_1 = require_retry_helper();
|
||||
var HTTPError = class extends Error {
|
||||
var HTTPError2 = class extends Error {
|
||||
constructor(httpStatusCode) {
|
||||
super(`Unexpected HTTP response: ${httpStatusCode}`);
|
||||
this.httpStatusCode = httpStatusCode;
|
||||
Object.setPrototypeOf(this, new.target.prototype);
|
||||
}
|
||||
};
|
||||
exports2.HTTPError = HTTPError;
|
||||
exports2.HTTPError = HTTPError2;
|
||||
var IS_WINDOWS = process.platform === "win32";
|
||||
var IS_MAC = process.platform === "darwin";
|
||||
var userAgent = "actions/tool-cache";
|
||||
@@ -80945,7 +80945,7 @@ var require_tool_cache = __commonJS({
|
||||
return yield retryHelper.execute(() => __awaiter4(this, void 0, void 0, function* () {
|
||||
return yield downloadToolAttempt(url2, dest || "", auth, headers);
|
||||
}), (err) => {
|
||||
if (err instanceof HTTPError && err.httpStatusCode) {
|
||||
if (err instanceof HTTPError2 && err.httpStatusCode) {
|
||||
if (err.httpStatusCode < 500 && err.httpStatusCode !== 408 && err.httpStatusCode !== 429) {
|
||||
return false;
|
||||
}
|
||||
@@ -80972,7 +80972,7 @@ var require_tool_cache = __commonJS({
|
||||
}
|
||||
const response = yield http.get(url2, headers);
|
||||
if (response.message.statusCode !== 200) {
|
||||
const err = new HTTPError(response.message.statusCode);
|
||||
const err = new HTTPError2(response.message.statusCode);
|
||||
core12.debug(`Failed to download from "${url2}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`);
|
||||
throw err;
|
||||
}
|
||||
@@ -88328,13 +88328,25 @@ function getRequiredEnvParam(paramName) {
|
||||
}
|
||||
return value;
|
||||
}
|
||||
var HTTPError = class extends Error {
|
||||
constructor(message, status) {
|
||||
super(message);
|
||||
this.status = status;
|
||||
}
|
||||
};
|
||||
var ConfigurationError = class extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
}
|
||||
};
|
||||
function isHTTPError(arg) {
|
||||
return arg?.status !== void 0 && Number.isInteger(arg.status);
|
||||
function asHTTPError(arg) {
|
||||
if (Number.isInteger(arg.status)) {
|
||||
return new HTTPError(arg.message, arg.status);
|
||||
}
|
||||
if (Number.isInteger(arg.httpStatusCode)) {
|
||||
return new HTTPError(arg.message, arg.httpStatusCode);
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
var cachedCodeQlVersion = void 0;
|
||||
function cacheCodeQlVersion(version) {
|
||||
@@ -88747,14 +88759,19 @@ function computeAutomationID(analysis_key, environment) {
|
||||
return automationID;
|
||||
}
|
||||
function wrapApiConfigurationError(e) {
|
||||
if (isHTTPError(e)) {
|
||||
if (e.message.includes("API rate limit exceeded for installation") || e.message.includes("commit not found") || e.message.includes("Resource not accessible by integration") || /ref .* not found in this repository/.test(e.message)) {
|
||||
return new ConfigurationError(e.message);
|
||||
} else if (e.message.includes("Bad credentials") || e.message.includes("Not Found")) {
|
||||
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)) {
|
||||
return new ConfigurationError(httpError.message);
|
||||
}
|
||||
if (httpError.message.includes("Bad credentials") || httpError.message.includes("Not Found")) {
|
||||
return new ConfigurationError(
|
||||
"Please check that your token is valid and has the required permissions: contents: read, security-events: write"
|
||||
);
|
||||
}
|
||||
if (httpError.status === 429) {
|
||||
return new ConfigurationError("API rate limit exceeded");
|
||||
}
|
||||
}
|
||||
return e;
|
||||
}
|
||||
@@ -92520,16 +92537,17 @@ async function uploadPayload(payload, repositoryNwo, logger, analysis) {
|
||||
logger.info("Successfully uploaded results");
|
||||
return response.data.id;
|
||||
} catch (e) {
|
||||
if (isHTTPError(e)) {
|
||||
switch (e.status) {
|
||||
const httpError = asHTTPError(e);
|
||||
if (httpError !== void 0) {
|
||||
switch (httpError.status) {
|
||||
case 403:
|
||||
core11.warning(e.message || GENERIC_403_MSG);
|
||||
core11.warning(httpError.message || GENERIC_403_MSG);
|
||||
break;
|
||||
case 404:
|
||||
core11.warning(e.message || GENERIC_404_MSG);
|
||||
core11.warning(httpError.message || GENERIC_404_MSG);
|
||||
break;
|
||||
default:
|
||||
core11.warning(e.message);
|
||||
core11.warning(httpError.message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user