1
1
import { Readable } from "stream" ;
2
- import { HTTPError } from "./exceptions" ;
2
+ import { HTTPError , HTTPFetchError } from "./exceptions" ;
3
3
import * as qs from "querystring" ;
4
4
5
5
const pkg = require ( "../package.json" ) ;
@@ -35,7 +35,7 @@ export default class HTTPFetchClient {
35
35
const response = await fetch ( requestUrl , {
36
36
headers : this . defaultHeaders ,
37
37
} ) ;
38
- this . checkResponseStatus ( response ) ;
38
+ await this . checkResponseStatus ( response ) ;
39
39
return response . json ( ) ;
40
40
}
41
41
@@ -75,7 +75,7 @@ export default class HTTPFetchClient {
75
75
} ,
76
76
body : JSON . stringify ( body ) ,
77
77
} ) ;
78
- this . checkResponseStatus ( response ) ;
78
+ await this . checkResponseStatus ( response ) ;
79
79
return this . responseParse ( response ) ;
80
80
}
81
81
@@ -99,7 +99,7 @@ export default class HTTPFetchClient {
99
99
} ,
100
100
body : JSON . stringify ( body ) ,
101
101
} ) ;
102
- this . checkResponseStatus ( response ) ;
102
+ await this . checkResponseStatus ( response ) ;
103
103
return this . responseParse ( response ) ;
104
104
}
105
105
@@ -113,7 +113,7 @@ export default class HTTPFetchClient {
113
113
} ,
114
114
body : qs . stringify ( body ) ,
115
115
} ) ;
116
- this . checkResponseStatus ( response ) ;
116
+ await this . checkResponseStatus ( response ) ;
117
117
return response . json ( ) ;
118
118
}
119
119
@@ -126,7 +126,7 @@ export default class HTTPFetchClient {
126
126
} ,
127
127
body : form ,
128
128
} ) ;
129
- this . checkResponseStatus ( response ) ;
129
+ await this . checkResponseStatus ( response ) ;
130
130
return response . json ( ) ;
131
131
}
132
132
@@ -144,7 +144,7 @@ export default class HTTPFetchClient {
144
144
} ,
145
145
body : form ,
146
146
} ) ;
147
- this . checkResponseStatus ( response ) ;
147
+ await this . checkResponseStatus ( response ) ;
148
148
return response . json ( ) ;
149
149
}
150
150
public async postBinaryContent < T > ( url : string , body : Blob ) : Promise < T > {
@@ -157,7 +157,7 @@ export default class HTTPFetchClient {
157
157
} ,
158
158
body : body ,
159
159
} ) ;
160
- this . checkResponseStatus ( response ) ;
160
+ await this . checkResponseStatus ( response ) ;
161
161
return response . json ( ) ;
162
162
}
163
163
@@ -172,17 +172,17 @@ export default class HTTPFetchClient {
172
172
...this . defaultHeaders ,
173
173
} ,
174
174
} ) ;
175
- this . checkResponseStatus ( response ) ;
175
+ await this . checkResponseStatus ( response ) ;
176
176
return response . json ( ) ;
177
177
}
178
178
179
- private checkResponseStatus ( response : Response ) {
179
+ private async checkResponseStatus ( response : Response ) {
180
180
if ( ! response . ok ) {
181
- throw new HTTPError (
182
- "HTTP request failed" ,
181
+ throw new HTTPFetchError (
183
182
response . status ,
184
183
response . statusText ,
185
- undefined ,
184
+ response . headers ,
185
+ await response . text ( )
186
186
) ;
187
187
}
188
188
}
0 commit comments