Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RealtimeChannel: populate invalid state error cause with the current errorReason, if set #1169

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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