Skip to content

Commit

Permalink
Catch errors in response.json()
Browse files Browse the repository at this point in the history
  • Loading branch information
robbevp committed Jan 25, 2021
1 parent 99a63f9 commit 2780eeb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/api/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const fetchRetry = require("fetch-retry")(fetch, {
export async function* indexGenerator(path, auth) {
let page = 1;
while (true) {
let response;
let response, result;
try {
response = await fetchRetry(`${baseURL}/${path}?page=${page}`, {
retries: 5,
Expand All @@ -19,10 +19,10 @@ export async function* indexGenerator(path, auth) {
"x-device-id": auth.device_id,
},
});
result = await response.json();
} catch (reason) {
throw { error: [reason] };
}
const result = await response.json();
if (response.ok && result) {
const loaded = new Date();
for (let obj in result) {
Expand All @@ -41,13 +41,13 @@ export async function* indexGenerator(path, auth) {
}

async function resolveRequest(path, options) {
let response;
let response, result;
try {
response = await fetchRetry(`${baseURL}/${path}`, options);
result = response.status === 204 ? true : await response.json();
} catch (reason) {
throw { error: [reason] };
}
const result = response.status === 204 ? true : await response.json();
if (response.ok) {
return result;
} else {
Expand Down

0 comments on commit 2780eeb

Please sign in to comment.