Skip to content

Commit 2813235

Browse files
authored
Set names of errors and reasonName for enums (#1385)
* Set names of errors and reasonName for enums * Create smart-mayflies-pay.md
1 parent 445a42e commit 2813235

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

.changeset/smart-mayflies-pay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"livekit-client": minor
3+
---
4+
5+
Populate name property of LiveKit errors and add reasonName for enums

src/room/errors.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ export class LivekitError extends Error {
55

66
constructor(code: number, message?: string) {
77
super(message || 'an error has occured');
8+
this.name = 'LiveKitError';
89
this.code = code;
910
}
1011
}
1112

12-
export const enum ConnectionErrorReason {
13+
export enum ConnectionErrorReason {
1314
NotAllowed,
1415
ServerUnreachable,
1516
InternalError,
@@ -24,52 +25,62 @@ export class ConnectionError extends LivekitError {
2425

2526
reason: ConnectionErrorReason;
2627

28+
reasonName: string;
29+
2730
constructor(
2831
message: string,
2932
reason: ConnectionErrorReason,
3033
status?: number,
3134
context?: unknown | DisconnectReason,
3235
) {
3336
super(1, message);
37+
this.name = 'ConnectionError';
3438
this.status = status;
3539
this.reason = reason;
3640
this.context = context;
41+
this.reasonName = ConnectionErrorReason[reason];
3742
}
3843
}
3944

4045
export class DeviceUnsupportedError extends LivekitError {
4146
constructor(message?: string) {
4247
super(21, message ?? 'device is unsupported');
48+
this.name = 'DeviceUnsupportedError';
4349
}
4450
}
4551

4652
export class TrackInvalidError extends LivekitError {
4753
constructor(message?: string) {
4854
super(20, message ?? 'track is invalid');
55+
this.name = 'TrackInvalidError';
4956
}
5057
}
5158

5259
export class UnsupportedServer extends LivekitError {
5360
constructor(message?: string) {
5461
super(10, message ?? 'unsupported server');
62+
this.name = 'UnsupportedServer';
5563
}
5664
}
5765

5866
export class UnexpectedConnectionState extends LivekitError {
5967
constructor(message?: string) {
6068
super(12, message ?? 'unexpected connection state');
69+
this.name = 'UnexpectedConnectionState';
6170
}
6271
}
6372

6473
export class NegotiationError extends LivekitError {
6574
constructor(message?: string) {
6675
super(13, message ?? 'unable to negotiate');
76+
this.name = 'NegotiationError';
6777
}
6878
}
6979

7080
export class PublishDataError extends LivekitError {
7181
constructor(message?: string) {
7282
super(14, message ?? 'unable to publish data');
83+
this.name = 'PublishDataError';
7384
}
7485
}
7586

@@ -80,9 +91,12 @@ export type RequestErrorReason =
8091
export class SignalRequestError extends LivekitError {
8192
reason: RequestErrorReason;
8293

94+
reasonName: string;
95+
8396
constructor(message: string, reason: RequestErrorReason) {
8497
super(15, message);
8598
this.reason = reason;
99+
this.reasonName = typeof reason === 'string' ? reason : RequestResponse_Reason[reason];
86100
}
87101
}
88102

0 commit comments

Comments
 (0)