Skip to content

Commit

Permalink
Improve error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
roj1512 committed May 30, 2024
1 parent 0217469 commit 28f9c60
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions 0_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,29 @@ export class MtkrutoError extends Error {
}

export class ConnectionError extends MtkrutoError {
constructor(...args: ConstructorParameters<typeof Error>) {
super(...args);
this.name = "ConnectionError";
}
}

export class AccessError extends MtkrutoError {
constructor(...args: ConstructorParameters<typeof Error>) {
super(...args);
this.name = "AccessError";
}
}

export class InputError extends MtkrutoError {
constructor(...args: ConstructorParameters<typeof Error>) {
super(...args);
this.name = "InputError";
}
}

export class TransportError extends MtkrutoError {
constructor(public readonly code: number) {
super(`Transport error: ${code}`);
this.name = "TransportError";
}
}
4 changes: 2 additions & 2 deletions 3_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ export interface TelegramErrorParams {
}

export class TelegramError extends MtkrutoError {
call: Api.AnyObject;
errorCode: number;
errorMessage: string;

constructor(params: TelegramErrorParams) {
super(`${params.error_code}: ${params.error_message} (${params.call._})`);
this.name = "TelegramError";
this.errorCode = params.error_code;
this.errorMessage = params.error_message;
this.call = params.call;
this.cause = params.call;
}
}

Expand Down

0 comments on commit 28f9c60

Please sign in to comment.