Skip to content

Commit

Permalink
RealtimeChannel: populate invalid state error cause with the current …
Browse files Browse the repository at this point in the history
…errorReason, if set
  • Loading branch information
SimonWoolf committed Mar 30, 2023
1 parent b2991c4 commit d22dbb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/common/lib/client/realtimechannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@ class RealtimeChannel extends Channel {
this._allChannelChanges = new EventEmitter();
}

static invalidStateError(state: string): ErrorInfo {
return new ErrorInfo('Channel operation failed as channel state is ' + state, 90001, 400);
invalidStateError(): ErrorInfo {
return new ErrorInfo(
'Channel operation failed as channel state is ' + this.state,
90001,
400,
this.errorReason || undefined
);
}

static processListenerArgs(args: unknown[]): any[] {
Expand Down Expand Up @@ -244,7 +249,7 @@ class RealtimeChannel extends Channel {
switch (state) {
case 'failed':
case 'suspended':
callback(ErrorInfo.fromValues(RealtimeChannel.invalidStateError(state)));
callback(ErrorInfo.fromValues(this.invalidStateError()));
break;
default: {
Logger.logAction(Logger.LOG_MICRO, 'RealtimeChannel.publish()', 'sending message; channel state is ' + state);
Expand Down Expand Up @@ -425,7 +430,7 @@ class RealtimeChannel extends Channel {
}

if (this.state === 'failed') {
callback?.(ErrorInfo.fromValues(RealtimeChannel.invalidStateError('failed')));
callback?.(ErrorInfo.fromValues(this.invalidStateError()));
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/common/lib/client/realtimepresence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function waitAttached(channel: RealtimeChannel, callback: ErrCallback, action: (
});
break;
default:
callback(ErrorInfo.fromValues(RealtimeChannel.invalidStateError(channel.state)));
callback(ErrorInfo.fromValues(channel.invalidStateError()));
}
}

Expand Down Expand Up @@ -248,7 +248,7 @@ class RealtimePresence extends Presence {
break;
}
default:
callback?.(RealtimeChannel.invalidStateError(channel.state));
callback?.(channel.invalidStateError());
}
}

Expand Down Expand Up @@ -533,7 +533,7 @@ class RealtimePresence extends Presence {
}

if (channel.state === 'failed') {
callback(ErrorInfo.fromValues(RealtimeChannel.invalidStateError('failed')));
callback(ErrorInfo.fromValues(channel.invalidStateError()));
return;
}

Expand Down

0 comments on commit d22dbb4

Please sign in to comment.