Clean up logging and fix error handling
This commit is contained in:
@@ -15,17 +15,21 @@ class ErrorMessage {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
get status() {
|
||||||
|
return this.error.status;
|
||||||
|
}
|
||||||
hasErrorWithCode(code) {
|
hasErrorWithCode(code) {
|
||||||
return this.githubErrors.some((err) => err.code == code);
|
return this.githubErrors.some((err) => err.code == code);
|
||||||
}
|
}
|
||||||
toString() {
|
toString() {
|
||||||
const message = this.error.message;
|
const message = this.error.message;
|
||||||
const errors = this.githubErrors;
|
const errors = this.githubErrors;
|
||||||
|
const status = this.status;
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
return `${message}\nErrors:\n${this.errorBulletedList(errors)}`;
|
return `Error ${status}: ${message}\nErrors:\n${this.errorBulletedList(errors)}`;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return message;
|
return `Error ${status}: ${message}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errorBulletedList(errors) {
|
errorBulletedList(errors) {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export class Action {
|
|||||||
if(this.inputs.allowUpdates) {
|
if(this.inputs.allowUpdates) {
|
||||||
try {
|
try {
|
||||||
const getResponse = await this.releases.getByTag(this.inputs.tag)
|
const getResponse = await this.releases.getByTag(this.inputs.tag)
|
||||||
return this.updateRelease(getResponse.data.id)
|
return await this.updateRelease(getResponse.data.id)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (this.noRelease(error)) {
|
if (this.noRelease(error)) {
|
||||||
return await this.createRelease()
|
return await this.createRelease()
|
||||||
@@ -54,7 +54,7 @@ export class Action {
|
|||||||
|
|
||||||
private noRelease(error:any): boolean {
|
private noRelease(error:any): boolean {
|
||||||
const errorMessage = new ErrorMessage(error)
|
const errorMessage = new ErrorMessage(error)
|
||||||
return errorMessage.hasErrorWithCode('missing')
|
return errorMessage.status == 404
|
||||||
}
|
}
|
||||||
|
|
||||||
private async updateRelease(id: number): Promise<string> {
|
private async updateRelease(id: number): Promise<string> {
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ export class ErrorMessage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get status():number {
|
||||||
|
return this.error.status
|
||||||
|
}
|
||||||
|
|
||||||
hasErrorWithCode(code: String): boolean {
|
hasErrorWithCode(code: String): boolean {
|
||||||
return this.githubErrors.some((err) => err.code == code)
|
return this.githubErrors.some((err) => err.code == code)
|
||||||
}
|
}
|
||||||
@@ -25,10 +29,11 @@ export class ErrorMessage {
|
|||||||
toString(): string {
|
toString(): string {
|
||||||
const message = this.error.message
|
const message = this.error.message
|
||||||
const errors = this.githubErrors
|
const errors = this.githubErrors
|
||||||
|
const status = this.status
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
return `${message}\nErrors:\n${this.errorBulletedList(errors)}`
|
return `Error ${status}: ${message}\nErrors:\n${this.errorBulletedList(errors)}`
|
||||||
} else {
|
} else {
|
||||||
return message
|
return `Error ${status}: ${message}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user