diff --git a/src/index.js b/src/index.js index 76a0e8c..cad9c0f 100644 --- a/src/index.js +++ b/src/index.js @@ -24,6 +24,19 @@ addEventListener('fetch', event => { try { const apiResponse = await fetch(apiRequest); + if (pathname === '/status' && apiResponse.ok) { + // If the request is to the /status path and the API request is successful, return a custom response + return new Response('API is up and running', { + status: 200, + statusText: 'OK' + })} else if (pathname === '/status' && !apiResponse.ok) { + // If the request is to the /status path and the API request fails, return a custom response + return new Response('API is down', { + status: 503, + statusText: 'Service Unavailable' + })}; + + if (apiResponse.status === 502 || apiResponse.status === 530) { // If the API request fails, return an error response return new Response('Service Unavailable', { @@ -35,10 +48,11 @@ addEventListener('fetch', event => { return apiResponse; } } catch (error) { + console.log(error); // If an error occurs during the API request, return an error response - return new Response('API backend is down temporarily', { - status: 420, - statusText: 'API Backend Downtime Error' + return new Response('Internal Server Error', { + status: 500, + statusText: 'Internal Server Error' }); } }