Skip to content

Commit

Permalink
feat(HiAnimeError): add json() for convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoshRitesh12 committed Oct 5, 2024
1 parent a772ede commit 3590da0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/hianime/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const DEFAULT_ERROR_STATUS = 500;
const DEFAULT_ERROR_MESSAGE = "Something went wrong";

export class HiAnimeError extends Error implements AniwatchError {
public scraper: string;
public scraper: string = DEFAULT_ERROR_MESSAGE;
public status: number = DEFAULT_ERROR_STATUS;

constructor(errMsg: string, scraperName: string, status?: number) {
Expand Down Expand Up @@ -46,13 +46,21 @@ export class HiAnimeError extends Error implements AniwatchError {
return new HiAnimeError(err?.message || DEFAULT_ERROR_MESSAGE, scraperName);
}

public json(): { status: number; message: string } {
return {
status: this.status,
message: this.message,
};
}

private logError() {
console.error(
ANSI_RED_COLOR +
JSON.stringify(
{
status: this.status,
scraper: this.scraper,
message: this?.message || DEFAULT_ERROR_MESSAGE,
message: this.message,
},
null,
2
Expand Down

0 comments on commit 3590da0

Please sign in to comment.