Skip to content

Commit 27fdf59

Browse files
feat: add operationID to OpenIMApiError and implement toJSON for serialization (#79)
1 parent 6ec29f6 commit 27fdf59

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/errors/OpenIMApiError.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,23 @@ export class OpenIMApiError extends Error {
22
name: string = 'OpenIMApiError';
33
code: number;
44
message: string;
5+
operationID: string;
56

6-
constructor(code: number, message: string) {
7+
constructor(code: number, message: string, operationID: string) {
78
super(message);
89
this.code = code;
910
this.message = message;
11+
this.operationID = operationID;
12+
}
13+
14+
// Error object's message and stack properties are non-enumerable by default.
15+
// Override toJSON() to ensure the message property is properly serialized.
16+
toJSON() {
17+
return {
18+
name: this.name,
19+
operationID: this.operationID,
20+
code: this.code,
21+
message: this.message,
22+
};
1023
}
1124
}

src/sdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class OpenIMSDK extends Emitter {
113113
* standardize error formats and make it easy for the business layer to determine
114114
* error sources based on the OpenIMApiError class.
115115
*/
116-
throw new OpenIMApiError(error.code, error.message);
116+
throw new OpenIMApiError(error.code, error.message, args[args.length - 1]);
117117
}
118118
}
119119

0 commit comments

Comments
 (0)