fixed api error issue

Fixed an issue where an api error would trigger the wrong response
This commit is contained in:
Jonas_Jones 2024-01-28 17:19:31 +01:00
parent fc7db7d5fd
commit 46a7fc6ae3

View file

@ -24,10 +24,7 @@ addEventListener('fetch', event => {
try { try {
const apiResponse = await fetch(apiRequest); const apiResponse = await fetch(apiRequest);
if (apiResponse.ok) { if (apiResponse.status === 502 || apiResponse.status === 530) {
// If the API request is successful, return the response
return apiResponse;
} else if (apiResponse.status === 502 || apiResponse.status === 530) {
// If the API request fails, return an error response // If the API request fails, return an error response
return new Response('Service Unavailable', { return new Response('Service Unavailable', {
status: 503, status: 503,
@ -35,10 +32,7 @@ addEventListener('fetch', event => {
}); });
} else { } else {
// If the API request fails, return an error response // 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!', { return apiResponse;
status: apiResponse.status,
statusText: apiResponse.statusText
});
} }
} catch (error) { } catch (error) {
// If an error occurs during the API request, return an error response // If an error occurs during the API request, return an error response