mirror of
https://github.com/ncipollo/release-action
synced 2026-09-07 20:04:03 +00:00
Fixes #301 Add remediation suggestion to 404 errors
This commit is contained in:
@@ -29,6 +29,31 @@ describe('ErrorMessage', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('has error with remediation', () => {
|
||||
it('provides remediation with 404 without errors', () => {
|
||||
const error = { status: 404, message: "message" }
|
||||
const githubError = new GithubError(error)
|
||||
expect(githubError.toString())
|
||||
.toBe('Error 404: message\nMake sure your github token has access to the repo and has permission to author releases')
|
||||
})
|
||||
|
||||
it('provides remediation with 404 with errors', () => {
|
||||
const error = {
|
||||
message: 'message',
|
||||
errors: [
|
||||
{
|
||||
code: 'missing',
|
||||
resource: 'release'
|
||||
}
|
||||
],
|
||||
status: 404
|
||||
}
|
||||
const githubError = new GithubError(error)
|
||||
expect(githubError.toString())
|
||||
.toBe('Error 404: message\nErrors:\n- release does not exist.\nMake sure your github token has access to the repo and has permission to author releases')
|
||||
})
|
||||
})
|
||||
|
||||
it('generates message with errors', () => {
|
||||
const error = {
|
||||
message: 'something bad happened',
|
||||
|
||||
Vendored
+233
-227
File diff suppressed because it is too large
Load Diff
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+8
-2
@@ -27,14 +27,20 @@ class GithubError {
|
||||
const errors = this.githubErrors;
|
||||
const status = this.status;
|
||||
if (errors.length > 0) {
|
||||
return `Error ${status}: ${message}\nErrors:\n${this.errorBulletedList(errors)}`;
|
||||
return `Error ${status}: ${message}\nErrors:\n${this.errorBulletedList(errors)}${this.remediation()}`;
|
||||
}
|
||||
else {
|
||||
return `Error ${status}: ${message}`;
|
||||
return `Error ${status}: ${message}${this.remediation()}`;
|
||||
}
|
||||
}
|
||||
errorBulletedList(errors) {
|
||||
return errors.map((err) => `- ${err}`).join("\n");
|
||||
}
|
||||
remediation() {
|
||||
if (this.status == 404) {
|
||||
return "\nMake sure your github token has access to the repo and has permission to author releases";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
exports.GithubError = GithubError;
|
||||
|
||||
+9
-2
@@ -31,14 +31,21 @@ export class GithubError {
|
||||
const errors = this.githubErrors
|
||||
const status = this.status
|
||||
if (errors.length > 0) {
|
||||
return `Error ${status}: ${message}\nErrors:\n${this.errorBulletedList(errors)}`
|
||||
return `Error ${status}: ${message}\nErrors:\n${this.errorBulletedList(errors)}${this.remediation()}`
|
||||
} else {
|
||||
return `Error ${status}: ${message}`
|
||||
return `Error ${status}: ${message}${this.remediation()}`
|
||||
}
|
||||
}
|
||||
|
||||
private errorBulletedList(errors: GithubErrorDetail[]): string {
|
||||
return errors.map((err) => `- ${err}`).join("\n")
|
||||
}
|
||||
|
||||
private remediation(): String {
|
||||
if (this.status == 404) {
|
||||
return "\nMake sure your github token has access to the repo and has permission to author releases"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user