Skip to content

Commit

Permalink
feat: add invalid access/trigger token error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nepalevov authored and pbek committed Mar 14, 2024
1 parent 011d091 commit 89abcef
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2869,6 +2869,16 @@ const pollPipeline = async (host, projectId, token, pipelineId, webUrl) => {
'Accept': 'application/json',
},
});

if (!response.ok) {
let errorMessage = `GitLab API returned status code ${response.status}.`;
if (response.status === 401) {
errorMessage = "Unauthorized: invalid/expired access token was used.";
}
core.setFailed(errorMessage);
break;
}

const data = await response.json();

status = data.status;
Expand Down Expand Up @@ -2917,6 +2927,15 @@ async function run() {
variables: variables,
}),
});

if (!response.ok) {
let errorMessage = `GitLab API returned status code ${response.status}.`;
if (response.status === 404) {
errorMessage = "The specified resource does not exist, or an invalid/expired trigger token was used.";
}
return core.setFailed(errorMessage);
}

const data = await response.json();

core.setOutput("id", data.id);
Expand Down
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ const pollPipeline = async (host, projectId, token, pipelineId, webUrl) => {
'Accept': 'application/json',
},
});

if (!response.ok) {
let errorMessage = `GitLab API returned status code ${response.status}.`;
if (response.status === 401) {
errorMessage = "Unauthorized: invalid/expired access token was used.";
}
core.setFailed(errorMessage);
break;
}

const data = await response.json();

status = data.status;
Expand Down Expand Up @@ -83,6 +93,15 @@ async function run() {
variables: variables,
}),
});

if (!response.ok) {
let errorMessage = `GitLab API returned status code ${response.status}.`;
if (response.status === 404) {
errorMessage = "The specified resource does not exist, or an invalid/expired trigger token was used.";
}
return core.setFailed(errorMessage);
}

const data = await response.json();

core.setOutput("id", data.id);
Expand Down

0 comments on commit 89abcef

Please sign in to comment.