Add try-catch to avoid failing requests
On GHES servers below version 3.8, the variables context is unavailable, resulting in 404 errors when calling the corresponding endpoint.
This commit is contained in:
@@ -2,9 +2,10 @@ import {data, DescriptionDictionary} from "@actions/expressions";
|
|||||||
import {Pair} from "@actions/expressions/data/expressiondata";
|
import {Pair} from "@actions/expressions/data/expressiondata";
|
||||||
import {StringData} from "@actions/expressions/data/index";
|
import {StringData} from "@actions/expressions/data/index";
|
||||||
import {WorkflowContext} from "@actions/languageservice/context/workflow-context";
|
import {WorkflowContext} from "@actions/languageservice/context/workflow-context";
|
||||||
import {warn} from "@actions/languageservice/log";
|
import {log, warn} from "@actions/languageservice/log";
|
||||||
import {isMapping, isString} from "@actions/workflow-parser";
|
import {isMapping, isString} from "@actions/workflow-parser";
|
||||||
import {Octokit} from "@octokit/rest";
|
import {Octokit} from "@octokit/rest";
|
||||||
|
import {RequestError} from "@octokit/types";
|
||||||
|
|
||||||
import {RepositoryContext} from "../initializationOptions";
|
import {RepositoryContext} from "../initializationOptions";
|
||||||
import {TTLCache} from "../utils/cache";
|
import {TTLCache} from "../utils/cache";
|
||||||
@@ -42,6 +43,7 @@ export async function getVariables(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const variablesContext = defaultContext || new DescriptionDictionary();
|
const variablesContext = defaultContext || new DescriptionDictionary();
|
||||||
|
try {
|
||||||
const variables = await getRemoteVariables(octokit, cache, repo, environmentName);
|
const variables = await getRemoteVariables(octokit, cache, repo, environmentName);
|
||||||
|
|
||||||
// Build combined map of variables
|
// Build combined map of variables
|
||||||
@@ -86,6 +88,13 @@ export async function getVariables(
|
|||||||
.forEach(variable => variablesContext?.add(variable.key, variable.value, variable.description));
|
.forEach(variable => variablesContext?.add(variable.key, variable.value, variable.description));
|
||||||
|
|
||||||
return variablesContext;
|
return variablesContext;
|
||||||
|
} catch (e: any) {
|
||||||
|
const requestError: RequestError = e;
|
||||||
|
if (requestError.name == "HttpError" && requestError.status == 404) {
|
||||||
|
log("Failure to request variables. Ignore if you're using GitHub Enterprise Server below version 3.8");
|
||||||
|
return variablesContext;
|
||||||
|
} else throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getRemoteVariables(
|
export async function getRemoteVariables(
|
||||||
|
|||||||
Reference in New Issue
Block a user