mirror of
https://github.com/softprops/action-gh-release.git
synced 2025-05-10 18:44:19 +00:00
Fix: error handling
- refactored the big `if/else` to exit early - added error handling for different errors while creating a release
This commit is contained in:
parent
5ce49bbfa3
commit
40bfa17351
1 changed files with 55 additions and 43 deletions
|
@ -278,7 +278,13 @@ export const release = async (
|
|||
});
|
||||
return release.data;
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
if (error.status !== 404) {
|
||||
console.log(
|
||||
`⚠️ Unexpected error fetching GitHub release for tag ${config.github_ref}: ${error}`
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
|
||||
const tag_name = tag;
|
||||
const name = config.input_name || tag;
|
||||
const body = releaseBody(config);
|
||||
|
@ -309,22 +315,28 @@ export const release = async (
|
|||
});
|
||||
return release.data;
|
||||
} catch (error) {
|
||||
// presume a race with competing metrix runs
|
||||
console.log(error.response.data)
|
||||
// presume a race with competing matrix runs
|
||||
console.log(`⚠️ GitHub release failed with status: ${error.status}\n`);
|
||||
console.log(`${JSON.stringify(error.response.data)}\n`);
|
||||
|
||||
switch (error.status) {
|
||||
case 403:
|
||||
console.log(
|
||||
`⚠️ GitHub release failed with status: ${
|
||||
error.status
|
||||
}\n${JSON.stringify(error.response.data.errors)}\nretrying... (${
|
||||
maxRetries - 1
|
||||
} retries remaining)`
|
||||
);
|
||||
return release(config, releaser, maxRetries - 1);
|
||||
}
|
||||
} else {
|
||||
console.log(
|
||||
`⚠️ Unexpected error fetching GitHub release for tag ${config.github_ref}: ${error}`
|
||||
"Skip retry — your token does not have the required permission to create a release"
|
||||
);
|
||||
throw error;
|
||||
|
||||
case 404:
|
||||
console.log("Skip retry - discussion category mismatch");
|
||||
throw error;
|
||||
|
||||
case 422:
|
||||
console.log("Skip retry - validation failed");
|
||||
throw error;
|
||||
}
|
||||
|
||||
console.log(`retrying... (${maxRetries - 1} retries remaining)`);
|
||||
return release(config, releaser, maxRetries - 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue