@@ -3217,7 +3217,8 @@ export type APIErrorResponse = {
3217
3217
export class ErrorFromResponse < T > extends Error {
3218
3218
public code : number | null ;
3219
3219
public status : number ;
3220
- public response : Pick < AxiosResponse < T > , 'data' | 'status' | 'statusText' | 'headers' > ;
3220
+ public response : AxiosResponse < T > ;
3221
+ public name = 'ErrorFromResponse' ;
3221
3222
3222
3223
constructor (
3223
3224
message : string ,
@@ -3227,20 +3228,38 @@ export class ErrorFromResponse<T> extends Error {
3227
3228
response,
3228
3229
} : {
3229
3230
code : ErrorFromResponse < T > [ 'code' ] ;
3230
- response : AxiosResponse < T > ;
3231
+ response : ErrorFromResponse < T > [ 'response' ] ;
3231
3232
status : ErrorFromResponse < T > [ 'status' ] ;
3232
3233
} ,
3233
3234
) {
3234
3235
super ( message ) ;
3235
3236
this . code = code ;
3236
- this . response = {
3237
- data : response . data ,
3238
- status : response . status ,
3239
- statusText : response . statusText ,
3240
- headers : response . headers ,
3241
- } ;
3237
+ this . response = response ;
3242
3238
this . status = status ;
3243
3239
}
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
+ }
3244
3263
}
3245
3264
3246
3265
export type QueryPollsResponse = {
0 commit comments