mirror of
https://github.com/JonasunderscoreJones/api.jonasjones.dev.git
synced 2025-10-22 19:59:17 +02:00
fixed api error issue
Fixed an issue where an api error would trigger the wrong response
This commit is contained in:
parent
fc7db7d5fd
commit
46a7fc6ae3
1 changed files with 2 additions and 8 deletions
10
src/index.js
10
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue