@@ -3216,7 +3216,8 @@ export type APIErrorResponse = {
3216
3216
export class ErrorFromResponse < T > extends Error {
3217
3217
public code : number | null ;
3218
3218
public status : number ;
3219
- public response : Pick < AxiosResponse < T > , 'data' | 'status' | 'statusText' | 'headers' > ;
3219
+ public response : AxiosResponse < T > ;
3220
+ public name = 'ErrorFromResponse' ;
3220
3221
3221
3222
constructor (
3222
3223
message : string ,
@@ -3226,20 +3227,38 @@ export class ErrorFromResponse<T> extends Error {
3226
3227
response,
3227
3228
} : {
3228
3229
code : ErrorFromResponse < T > [ 'code' ] ;
3229
- response : AxiosResponse < T > ;
3230
+ response : ErrorFromResponse < T > [ 'response' ] ;
3230
3231
status : ErrorFromResponse < T > [ 'status' ] ;
3231
3232
} ,
3232
3233
) {
3233
3234
super ( message ) ;
3234
3235
this . code = code ;
3235
- this . response = {
3236
- data : response . data ,
3237
- status : response . status ,
3238
- statusText : response . statusText ,
3239
- headers : response . headers ,
3240
- } ;
3236
+ this . response = response ;
3241
3237
this . status = status ;
3242
3238
}
3239
+
3240
+ // Vitest helper (serialized errors are too large to read)
3241
+ // https://github.com/vitest-dev/vitest/blob/v3.1.3/packages/utils/src/error.ts#L60-L62
3242
+ toJSON ( ) {
3243
+ const extra = [
3244
+ [ 'status' , this . status ] ,
3245
+ [ 'code' , this . code ] ,
3246
+ ] as const ;
3247
+
3248
+ const joinable = [ ] ;
3249
+
3250
+ for ( const [ key , value ] of extra ) {
3251
+ if ( typeof value !== 'undefined' && value !== null ) {
3252
+ joinable . push ( `${ key } : ${ value } ` ) ;
3253
+ }
3254
+ }
3255
+
3256
+ return {
3257
+ message : `(${ joinable . join ( ', ' ) } ) - ${ this . message } ` ,
3258
+ stack : this . stack ,
3259
+ name : this . name ,
3260
+ } ;
3261
+ }
3243
3262
}
3244
3263
3245
3264
export type QueryPollsResponse = {
0 commit comments