Skip to content

Commit

Permalink
makeRestRequest parses text and JSON responses
Browse files Browse the repository at this point in the history
Had previously been calling .json() on all responses, even if they
were strings. Can now handle JSON and string responses.

resolving #14
  • Loading branch information
friendofdog committed Apr 19, 2021
1 parent 47ea411 commit ba806cc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions source/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ export async function makeRestRequest(path: string, redirect = true): Promise<an
}
}
const response = await fetch(encodeURI(REST_API_URL + path), options);
const result = await response.json();
return result;

let result = await response.text();
try {
result = JSON.parse(result);
}
finally {
return result;
}
} catch (error) {
throw new wikiError(error);
}
Expand Down

0 comments on commit ba806cc

Please sign in to comment.