From 46a7fc6ae31dc87f26ea79c0bb4702aaa9d4c025 Mon Sep 17 00:00:00 2001 From: Jonas_Jones <91549607+JonasunderscoreJones@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:19:31 +0100 Subject: [PATCH] fixed api error issue Fixed an issue where an api error would trigger the wrong response --- src/index.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index bc08b0a..112137e 100644 --- a/src/index.js +++ b/src/index.js @@ -24,10 +24,7 @@ addEventListener('fetch', event => { try { const apiResponse = await fetch(apiRequest); - if (apiResponse.ok) { - // If the API request is successful, return the response - return apiResponse; - } else if (apiResponse.status === 502 || apiResponse.status === 530) { + if (apiResponse.status === 502 || apiResponse.status === 530) { // If the API request fails, return an error response return new Response('Service Unavailable', { status: 503, @@ -35,10 +32,7 @@ addEventListener('fetch', event => { }); } else { // If the API request fails, return an error response - return new Response('API backend went down just now :( It should be back up in a matter of seconds!', { - status: apiResponse.status, - statusText: apiResponse.statusText - }); + return apiResponse; } } catch (error) { // If an error occurs during the API request, return an error response