Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,18 @@ export function rise(
let payload;
try {
const contentType = response.headers.get('Content-Type');
const isJsonContent = contentType && contentType.includes('application/json');
const isTextContent = contentType && contentType.includes('text');
if (isTextContent) {
if (isJsonContent) {
try {
payload = await response.json();
} catch (jsonError) {
payload = { [errorroot]: { message: 'Received unparsable JSON response from the server.' } };
}
} else if (isTextContent) {
payload = { [errorroot]: { message: await response.text() } };
} else {
payload = await response.json();
payload = { [errorroot]: { message: 'Unsupported content type in server response.' } };
}
} catch (e) {
throw new options.ErrorClass(response.statusText, response.status, e);
Expand Down