@@ -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
4045export class DeviceUnsupportedError extends LivekitError {
4146 constructor ( message ?: string ) {
4247 super ( 21 , message ?? 'device is unsupported' ) ;
48+ this . name = 'DeviceUnsupportedError' ;
4349 }
4450}
4551
4652export class TrackInvalidError extends LivekitError {
4753 constructor ( message ?: string ) {
4854 super ( 20 , message ?? 'track is invalid' ) ;
55+ this . name = 'TrackInvalidError' ;
4956 }
5057}
5158
5259export class UnsupportedServer extends LivekitError {
5360 constructor ( message ?: string ) {
5461 super ( 10 , message ?? 'unsupported server' ) ;
62+ this . name = 'UnsupportedServer' ;
5563 }
5664}
5765
5866export class UnexpectedConnectionState extends LivekitError {
5967 constructor ( message ?: string ) {
6068 super ( 12 , message ?? 'unexpected connection state' ) ;
69+ this . name = 'UnexpectedConnectionState' ;
6170 }
6271}
6372
6473export class NegotiationError extends LivekitError {
6574 constructor ( message ?: string ) {
6675 super ( 13 , message ?? 'unable to negotiate' ) ;
76+ this . name = 'NegotiationError' ;
6777 }
6878}
6979
7080export 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 =
8091export 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