File tree Expand file tree Collapse file tree 1 file changed +19
-11
lines changed
Expand file tree Collapse file tree 1 file changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -209,25 +209,33 @@ async function tryParseJson(textValue: string) {
209209 }
210210}
211211
212- export const parseResponse = ( response : ResponseBody ) : Promise < ResponseBody > => {
213- if ( response instanceof Response && response . headers ) {
214- const headers = getHeaders ( response )
215- const contentType = getContentType ( headers ) ;
212+ export const parseResponse = async ( response : ResponseBody ) : Promise < ResponseBody > => {
213+ if ( ! ( response instanceof Response ) ) { return response ; }
214+
215+ const headers = getHeaders ( response ) ;
216+ const contentType = getContentType ( headers ) ;
217+
218+ try {
216219 switch ( contentType ) {
217- case 'application/json' :
218- return response . text ( ) . then ( tryParseJson ) ;
220+ case 'application/json' : {
221+ const text = await response . text ( ) ;
222+ return tryParseJson ( text ) ;
223+ }
219224 case 'application/xml' :
220225 case 'text/html' :
221226 case 'text/csv' :
222227 case 'text/plain' :
223- return response . text ( ) ;
224-
228+ return await response . text ( ) ;
225229 default :
226- return Promise . resolve ( response ) ;
230+ if ( response . status === 204 ) {
231+ return '' ;
232+ }
233+ return await response . text ( ) ;
227234 }
235+ } catch {
236+ return '' ;
228237 }
229- return Promise . resolve ( response ) ;
230- }
238+ } ;
231239
232240/**
233241 * Check if query attempts to download from OneDrive's /content API or reporting API
You can’t perform that action at this time.
0 commit comments