Skip to content

Commit

Permalink
Merge pull request #1129 from ably/errorinfo-extends-error
Browse files Browse the repository at this point in the history
fix: `ErrorInfo` extends `Error`
  • Loading branch information
owenpearson authored Feb 27, 2023
2 parents 5854ecd + 59aca8c commit 279488a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 1 addition & 5 deletions src/common/lib/client/realtimechannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ class RealtimeChannel extends Channel {
}

static invalidStateError(state: string): ErrorInfo {
return {
statusCode: 400,
code: 90001,
message: 'Channel operation failed as channel state is ' + state,
};
return new ErrorInfo('Channel operation failed as channel state is ' + state, 90001, 400);
}

static processListenerArgs(args: unknown[]): any[] {
Expand Down
8 changes: 5 additions & 3 deletions src/common/lib/types/errorinfo.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import Platform from 'common/platform';
import * as Utils from '../util/utils';

export default class ErrorInfo {
message: string;
export default class ErrorInfo extends Error {
code: number | null;
statusCode?: number;
cause?: string | Error | ErrorInfo;
href?: string;

constructor(message: string, code: number | null, statusCode?: number, cause?: string | Error | ErrorInfo) {
this.message = message;
super(message);
if (typeof Object.setPrototypeOf !== 'undefined') {
Object.setPrototypeOf(this, ErrorInfo.prototype);
}
this.code = code;
this.statusCode = statusCode;
this.cause = cause;
Expand Down

0 comments on commit 279488a

Please sign in to comment.