Skip to content

Commit

Permalink
Clean up logging and fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Cipollo committed Dec 13, 2019
1 parent b25a3c6 commit 734853d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
8 changes: 6 additions & 2 deletions lib/ErrorMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ class ErrorMessage {
return [];
}
}
get status() {
return this.error.status;
}
hasErrorWithCode(code) {
return this.githubErrors.some((err) => err.code == code);
}
toString() {
const message = this.error.message;
const errors = this.githubErrors;
const status = this.status;
if (errors.length > 0) {
return `${message}\nErrors:\n${this.errorBulletedList(errors)}`;
return `Error ${status}: ${message}\nErrors:\n${this.errorBulletedList(errors)}`;
}
else {
return message;
return `Error ${status}: ${message}`;
}
}
errorBulletedList(errors) {
Expand Down
4 changes: 2 additions & 2 deletions src/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class Action {
if(this.inputs.allowUpdates) {
try {
const getResponse = await this.releases.getByTag(this.inputs.tag)
return this.updateRelease(getResponse.data.id)
return await this.updateRelease(getResponse.data.id)
} catch (error) {
if (this.noRelease(error)) {
return await this.createRelease()
Expand All @@ -54,7 +54,7 @@ export class Action {

private noRelease(error:any): boolean {
const errorMessage = new ErrorMessage(error)
return errorMessage.hasErrorWithCode('missing')
return errorMessage.status == 404
}

private async updateRelease(id: number): Promise<string> {
Expand Down
9 changes: 7 additions & 2 deletions src/ErrorMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ export class ErrorMessage {
}
}

get status():number {
return this.error.status
}

hasErrorWithCode(code: String): boolean {
return this.githubErrors.some((err) => err.code == code)
}

toString(): string {
const message = this.error.message
const errors = this.githubErrors
const status = this.status
if (errors.length > 0) {
return `${message}\nErrors:\n${this.errorBulletedList(errors)}`
return `Error ${status}: ${message}\nErrors:\n${this.errorBulletedList(errors)}`
} else {
return message
return `Error ${status}: ${message}`
}
}

Expand Down

0 comments on commit 734853d

Please sign in to comment.