mirror of
https://github.com/joelwmale/webhook-action.git
synced 2026-08-24 00:49:00 +08:00
v2.0.2
This commit is contained in:
+16
-6
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user