Skip to content

Commit 8f6948f

Browse files
feat: add toJSON to ErrorFromResponse class (#1540)
## Description of the changes, What, Why and How? Vitest [serializes errors](https://github.com/vitest-dev/vitest/blob/v3.1.3/packages/utils/src/error.ts#L60-L62) and our error instance keeps a ton of data (from Axios) which - when serialized - pollutes test logs with unreadable messages (see GetStream/chat#8211 QA runs for "before"). (it's way longer, see scrollbar) after: ![image](https://github.com/user-attachments/assets/bb8460f2-9b09-416a-8491-590fd8870608) This needs to be copied over to video SDK as well.
1 parent 5fff918 commit 8f6948f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/types.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3218,6 +3218,7 @@ export class ErrorFromResponse<T> extends Error {
32183218
public code: number | null;
32193219
public status: number;
32203220
public response: AxiosResponse<T>;
3221+
public name = 'ErrorFromResponse';
32213222

32223223
constructor(
32233224
message: string,
@@ -3236,6 +3237,29 @@ export class ErrorFromResponse<T> extends Error {
32363237
this.response = response;
32373238
this.status = status;
32383239
}
3240+
3241+
// Vitest helper (serialized errors are too large to read)
3242+
// https://github.com/vitest-dev/vitest/blob/v3.1.3/packages/utils/src/error.ts#L60-L62
3243+
toJSON() {
3244+
const extra = [
3245+
['status', this.status],
3246+
['code', this.code],
3247+
] as const;
3248+
3249+
const joinable = [];
3250+
3251+
for (const [key, value] of extra) {
3252+
if (typeof value !== 'undefined' && value !== null) {
3253+
joinable.push(`${key}: ${value}`);
3254+
}
3255+
}
3256+
3257+
return {
3258+
message: `(${joinable.join(', ')}) - ${this.message}`,
3259+
stack: this.stack,
3260+
name: this.name,
3261+
};
3262+
}
32393263
}
32403264

32413265
export type QueryPollsResponse = {

0 commit comments

Comments
 (0)