Fixes #4 Improve error reporting
This commit is contained in:
33
src/ErrorMessage.ts
Normal file
33
src/ErrorMessage.ts
Normal 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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user