This commit is contained in:
Joel Male
2020-08-29 11:10:10 +10:00
parent aff8b23be8
commit 144f9e1d68
9 changed files with 36 additions and 12 deletions
+16 -6
View File
@@ -9,7 +9,8 @@ async function run() {
if (!url) {
// validate a url
core.setFailed('A url is required to run this action.');
return;
// error
throw new Error('A url is required to run this action.');
}
// initial info
@@ -21,20 +22,29 @@ async function run() {
// make the request
http.make(url, headers, body)
.then((res) => {
// if the status code is not 2xx
if (res.status >= 400) {
// throw an error
error(res.status);
}
// output the status
core.setOutput('statusCode', res.status);
// throw error on error status codes
if (res.status >= 400)
throw new Error(`Failing with code: ${res.status}`)
// report on the status code
core.info(`Received status code: ${res.status}`);
// debug end
core.info((new Date()).toTimeString());
})
.catch((err) => {
// set the action to failed
core.setFailed(`Received status code: ${err.status}`);
error(err.status);
});
}
function error(statusCode) {
// set the action to failed
core.setFailed(`Received status code: ${statusCode}`);
// throw an error
throw new Error(`Request failed with status code: ${statusCode}`);
}
run();