refactor: enhance error message of promise reject
This commit is contained in:
parent
ab1914bc1a
commit
947ed8e60f
3 changed files with 7 additions and 7 deletions
6
.github/workflows/test.yml
vendored
6
.github/workflows/test.yml
vendored
|
|
@ -27,8 +27,10 @@ jobs:
|
||||||
needs: test
|
needs: test
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
hugo-version: ['latest', '0.58.2']
|
hugo-version: ['latest']
|
||||||
extended: [true, false]
|
extended: [true]
|
||||||
|
# hugo-version: ['latest', '0.58.2']
|
||||||
|
# extended: [true, false]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,13 @@ function getLatestVersion() {
|
||||||
const url = "https://formulae.brew.sh/api/formula/hugo.json";
|
const url = "https://formulae.brew.sh/api/formula/hugo.json";
|
||||||
xhr.open("GET", url);
|
xhr.open("GET", url);
|
||||||
xhr.send();
|
xhr.send();
|
||||||
|
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||||
const result = JSON.parse(xhr.responseText);
|
const result = JSON.parse(xhr.responseText);
|
||||||
const latestVersion = result.versions.stable;
|
const latestVersion = result.versions.stable;
|
||||||
resolve(latestVersion);
|
resolve(latestVersion);
|
||||||
} else if (xhr.readyState === 4 && xhr.status !== 200) {
|
} else if (xhr.readyState === 4 && xhr.status !== 200) {
|
||||||
reject(`ERROR: got status ${xhr.status}`);
|
reject(`ERROR: got status ${xhr.status} of ${url}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
5
index.js
5
index.js
|
|
@ -14,9 +14,8 @@ async function run() {
|
||||||
}
|
}
|
||||||
console.log(`Hugo version: ${hugoVersion}`);
|
console.log(`Hugo version: ${hugoVersion}`);
|
||||||
|
|
||||||
let extended = core.getInput("extended");
|
const extended = core.getInput("extended");
|
||||||
console.log(`Hugo extended: ${extended}`);
|
console.log(`Hugo extended: ${extended}`);
|
||||||
|
|
||||||
let extendedStr = "";
|
let extendedStr = "";
|
||||||
if (extended === "true") {
|
if (extended === "true") {
|
||||||
extendedStr = "extended_";
|
extendedStr = "extended_";
|
||||||
|
|
@ -41,7 +40,7 @@ async function run() {
|
||||||
await io.mv(`${hugoExtractedFolder}/hugo`, hugoPath);
|
await io.mv(`${hugoExtractedFolder}/hugo`, hugoPath);
|
||||||
},
|
},
|
||||||
function(error) {
|
function(error) {
|
||||||
console.error(error);
|
core.setFailed(error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue