@@ -62,41 +62,43 @@ function enhanceAxiosError(
62
62
return error ;
63
63
}
64
64
65
- export async function createAxiosErrorFromFetchResp ( response : Response ) : Promise < AxiosError > {
65
+ export async function createAxiosErrorFromFetchResp ( responseOrError : Response ) : Promise < AxiosError > {
66
66
const config = {
67
- url : response . url ,
68
- headers : response . headers
67
+ url : responseOrError . url ,
68
+ headers : responseOrError . headers
69
69
} ;
70
- const isProperResponse = "status" in response ;
70
+ const isResponse = "status" in responseOrError ;
71
71
let axiosResponse ;
72
- if ( isProperResponse ) {
72
+ if ( isResponse ) {
73
73
let data ;
74
- const contentType = response . headers . get ( "content-type" ) ;
74
+ const contentType = responseOrError . headers . get ( "content-type" ) ;
75
75
if ( ! contentType || contentType . includes ( "application/json" ) ) {
76
76
try {
77
- data = await response . json ( ) ;
77
+ data = await responseOrError . json ( ) ;
78
78
} catch {
79
- data = await response . text ( ) ;
79
+ data = await responseOrError . text ( ) ;
80
80
}
81
81
} else if ( contentType . includes ( "text/" ) ) {
82
- data = await response . text ( ) ;
82
+ data = await responseOrError . text ( ) ;
83
83
} else {
84
- data = await response . blob ( ) ;
84
+ data = await responseOrError . blob ( ) ;
85
85
}
86
86
87
87
axiosResponse = {
88
88
data,
89
- status : response . status ,
90
- statusText : response . statusText ,
91
- headers : response . headers ,
89
+ status : responseOrError . status ,
90
+ statusText : responseOrError . statusText ,
91
+ headers : responseOrError . headers ,
92
92
config : config ,
93
93
request : undefined
94
94
} ;
95
95
}
96
96
return enhanceAxiosError (
97
- "status" in response ? new Error ( "Request failed with status code " + response . status ) : response ,
97
+ "status" in responseOrError
98
+ ? new Error ( "Request failed with status code " + responseOrError . status )
99
+ : responseOrError ,
98
100
config ,
99
- ( response as any ) . code ,
101
+ ( responseOrError as any ) . code ,
100
102
undefined ,
101
103
axiosResponse
102
104
) ;
0 commit comments