Skip to content

Commit b9b17a1

Browse files
committed
parse serializable response
1 parent be1f4d7 commit b9b17a1

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/app/services/actions/query-action-creator-util.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)