Fixes #4 Improve error reporting

This commit is contained in:
Nick Cipollo
2019-12-12 14:30:08 -05:00
parent c4fce56188
commit dba5ad58d6
5 changed files with 220 additions and 1 deletions

33
src/ErrorMessage.ts Normal file
View File

@@ -0,0 +1,33 @@
import { GithubError } from "./GithubError"
export class ErrorMessage {
error: any
constructor(error: any) {
this.error = error
}
toString(): string {
const message = this.error.message
const errors = this.githubErrors()
if (errors.length > 0) {
return `${message}\nErrors:\n${this.errorBulletedList(errors)}`
} else {
return message
}
}
githubErrors(): GithubError[] {
const errors = this.error.errors
if (errors instanceof Array) {
return errors.map((err) => new GithubError(err))
} else {
return []
}
}
errorBulletedList(errors: GithubError[]): string {
return errors.map((err) => `- ${err}`).join("\n")
}
}