Skip to content

Commit

Permalink
fix: Fix instanceof operator for error classes
Browse files Browse the repository at this point in the history
  • Loading branch information
neet committed Dec 23, 2022
1 parent 81afb29 commit 7893b4d
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/errors/masto-deserialize-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ export class MastoDeserializeError extends MastoError {
props?: MastoErrorProps,
) {
super(message, props);
Object.setPrototypeOf(this, MastoDeserializeError.prototype);
}
}
2 changes: 2 additions & 0 deletions src/errors/masto-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export abstract class MastoError extends Error {
*/
constructor(message: string, props: MastoErrorProps = {}) {
super(message, { cause: props.cause });
Object.setPrototypeOf(this, MastoError.prototype);

this.description = props.description;
this.details = props.details;
}
Expand Down
1 change: 1 addition & 0 deletions src/errors/masto-http-conflict-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export class MastoHttpConflictError extends MastoHttpError {

constructor(message: string, props?: MastoErrorProps) {
super(message, 409, props);
Object.setPrototypeOf(this, MastoHttpConflictError.prototype);
}
}
1 change: 1 addition & 0 deletions src/errors/masto-http-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export abstract class MastoHttpError extends MastoError {

constructor(message: string, statusCode: number, props?: MastoErrorProps) {
super(message, props);
Object.setPrototypeOf(this, MastoHttpError.prototype);
this.statusCode = statusCode;
}
}
1 change: 1 addition & 0 deletions src/errors/masto-http-forbidden-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export class MastoHttpForbiddenError extends MastoHttpError {

constructor(message: string, props?: MastoErrorProps) {
super(message, 403, props);
Object.setPrototypeOf(this, MastoHttpForbiddenError.prototype);
}
}
1 change: 1 addition & 0 deletions src/errors/masto-http-gone-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export class MastoHttpGoneError extends MastoHttpError {

constructor(message: string, props?: MastoErrorProps) {
super(message, 410, props);
Object.setPrototypeOf(this, MastoHttpGoneError.prototype);
}
}
3 changes: 2 additions & 1 deletion src/errors/masto-http-not-found-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { MastoHttpError } from './masto-http-error';
* Mastodon not found error class
*/
export class MastoHttpNotFoundError extends MastoHttpError {
override name = 'MastoNotFoundError';
override name = 'MastoHttpNotFoundError';

constructor(message: string, props?: MastoErrorProps) {
super(message, 404, props);
Object.setPrototypeOf(this, MastoHttpNotFoundError.prototype);
}
}
4 changes: 3 additions & 1 deletion src/errors/masto-http-rate-limit-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type MastoRateLimitErrorProps = MastoErrorProps & {
* Mastodon rate limit error class
*/
export class MastoHttpRateLimitError extends MastoHttpError {
override name = 'MastoRateLimitError';
override name = 'MastoHttpRateLimitError';

/** Number of requests permitted per time period */
readonly limit: number;
Expand All @@ -22,6 +22,8 @@ export class MastoHttpRateLimitError extends MastoHttpError {

constructor(message: string, props: MastoRateLimitErrorProps) {
super(message, 429, props);
Object.setPrototypeOf(this, MastoHttpRateLimitError.prototype);

this.limit = props?.limit;
this.remaining = props?.remaining;
this.reset = props?.reset;
Expand Down
3 changes: 2 additions & 1 deletion src/errors/masto-http-unauthorized-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { MastoHttpError } from './masto-http-error';
* Mastodon unauthorized error class
*/
export class MastoHttpUnauthorizedError extends MastoHttpError {
override name = 'MastoUnauthorizedError';
override name = 'MastoHttpUnauthorizedError';

constructor(message: string, props: MastoErrorProps) {
super(message, 401, props);
Object.setPrototypeOf(this, MastoHttpUnauthorizedError.prototype);
}
}
1 change: 1 addition & 0 deletions src/errors/masto-http-unexpected-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export class MastoHttpUnexpectedError extends MastoHttpError {

constructor(message: string, statusCode: number, props?: MastoErrorProps) {
super(message, statusCode, props);
Object.setPrototypeOf(this, MastoHttpUnexpectedError.prototype);
}
}
1 change: 1 addition & 0 deletions src/errors/masto-http-unprocessable-entity-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export class MastoHttpUnprocessableEntityError extends MastoHttpError {

constructor(message: string, props: MastoErrorProps) {
super(message, 422, props);
Object.setPrototypeOf(this, MastoHttpUnprocessableEntityError.prototype);
}
}
1 change: 1 addition & 0 deletions src/errors/masto-timeout-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export class MastoTimeoutError extends MastoError {

constructor(message: string, props?: MastoErrorProps) {
super(message, props);
Object.setPrototypeOf(this, MastoTimeoutError.prototype);
}
}
1 change: 1 addition & 0 deletions src/errors/masto-unexpected-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export class MastoUnexpectedError extends MastoError {

constructor(message: string, props: MastoErrorProps = {}) {
super(message, { cause: props.cause });
Object.setPrototypeOf(this, MastoUnexpectedError.prototype);
}
}
1 change: 1 addition & 0 deletions src/errors/masto-version-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export class MastoVersionError extends MastoError {

constructor(message: string, props?: MastoErrorProps) {
super(message, props);
Object.setPrototypeOf(this, MastoVersionError.prototype);
}
}

0 comments on commit 7893b4d

Please sign in to comment.