diff --git a/scripts/utils.js b/scripts/utils.js
index cb9ede5..1df55e2 100644
--- a/scripts/utils.js
+++ b/scripts/utils.js
@@ -207,27 +207,31 @@ export async function requestAPI (path, method, body = null) {
}
async function request (url, content) {
- const response = await fetch(url, content);
- const contentType = response.headers.get("Content-Type");
- let data = null;
- if (contentType.includes("application/json")) {
- data = await response.json();
- data.status = response.status;
+ try {
+ const response = await fetch(url, content);
+ const contentType = response.headers.get("Content-Type");
+ let data = null;
+ if (contentType.includes("application/json")) {
+ data = await response.json();
+ data.status = response.status;
+ }
+ else if (contentType.includes("text/html")) {
+ data = { data: await response.text() };
+ data.status = response.status;
+ }
+ else {
+ data = response;
+ }
+ if (!response.ok) {
+ return { status: response.status, error: data ? data.error : response.status };
+ }
+ else {
+ data.status = response.status;
+ return data || response;
+ }
}
- else if (contentType.includes("text/html")) {
- data = { data: await response.text() };
- data.status = response.status;
- }
- else {
- data = response;
- }
-
- if (!response.ok) {
- return { status: response.status, error: data ? data.error : response.status };
- }
- else {
- data.status = response.status;
- return data || response;
+ catch (error) {
+ return {status: 400, error: error};
}
}