handle API error

This commit is contained in:
Viet Huynh
2023-09-09 21:24:02 +07:00
parent 53803edc6e
commit 61d6c03704
2 changed files with 10 additions and 2 deletions
+6 -2
View File
@@ -63,8 +63,12 @@ const createZeroTrustListsAtOnce = async (items) => {
listNumber++; listNumber++;
} }
await Promise.all(requests); try {
console.log(`Created ${totalListNumber} lists`); await Promise.all(requests);
console.log(`Created ${totalListNumber} lists`);
} catch (err) {
console.error(`Error occurred while creating lists - ${err.toString()}`);
}
}; };
/** /**
+4
View File
@@ -17,6 +17,10 @@ const request = async (url, options) => {
...options, ...options,
}); });
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json(); return response.json();
}; };