Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/error #152

Merged
merged 12 commits into from
Oct 15, 2024
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ data
.cargo
.vscode
server/tmp

# If someone accidentally makes these in root
node_modules
yarn.lock
48 changes: 36 additions & 12 deletions client/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ export async function getRequest<T>(path: string, auth: string): Promise<FetchRe
headers: createHeaders(auth, true),
};
const response = await fetch(`${BACKEND_URL}${path}`, options);
const data = await response.json();
return { status: response.status, error: data.error ? data.error : '', data };

try {
const data = await response.json();
return { status: response.status, error: data.error ? data.error : '', data };
} catch (jsonError) {
console.error('JSON parsing error:', jsonError);
return { status: response.status, error: 'Error parsing response', data: null };
}
// eslint-disable-next-line
} catch (error: any) {
console.error(error);
return { status: 404, error: error, data: null };
return { status: 404, error: 'Network connection issue', data: null };
}
}

Expand All @@ -31,12 +37,18 @@ export async function postRequest<T>(
body: body ? JSON.stringify(body) : null,
};
const response = await fetch(`${BACKEND_URL}${path}`, options);
const data = await response.json();
return { status: response.status, error: data.error ? data.error : '', data };

try {
const data = await response.json();
return { status: response.status, error: data.error ? data.error : '', data };
} catch (jsonError) {
console.error('JSON parsing error:', jsonError);
return { status: response.status, error: 'Error parsing response', data: null };
}
// eslint-disable-next-line
} catch (error: any) {
console.error(error);
return { status: 404, error: error, data: null };
return { status: 404, error: 'Network connection issue', data: null };
}
}

Expand All @@ -53,12 +65,18 @@ export async function putRequest<T>(
body: body ? JSON.stringify(body) : null,
};
const response = await fetch(`${BACKEND_URL}${path}`, options);
const data = await response.json();
return { status: response.status, error: data.error ? data.error : '', data };

try {
const data = await response.json();
return { status: response.status, error: data.error ? data.error : '', data };
} catch (jsonError) {
console.error('JSON parsing error:', jsonError);
return { status: response.status, error: 'Error parsing response', data: null };
}
// eslint-disable-next-line
} catch (error: any) {
console.error(error);
return { status: 404, error: error, data: null };
return { status: 404, error: 'Network connection issue', data: null };
}
}

Expand All @@ -72,12 +90,18 @@ export async function deleteRequest(
headers: createHeaders(auth, true),
};
const response = await fetch(`${BACKEND_URL}${path}`, options);
const data = await response.json();
return { status: response.status, error: data.error ? data.error : '', data };

try {
const data = await response.json();
return { status: response.status, error: data.error ? data.error : '', data };
} catch (jsonError) {
console.error('JSON parsing error:', jsonError);
return { status: response.status, error: 'Error parsing response', data: null };
}
// eslint-disable-next-line
} catch (error: any) {
console.error(error);
return { status: 404, error: error, data: null };
return { status: 404, error: 'Network connection issue', data: null };
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/judge/live.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ const JudgeLive = () => {
<Button
type="primary"
className="bg-error mr-2 py-1 text-xl rounded-xl basis-2/5 disabled:bg-backgroundDark hover:bg-errorDark"
disabled={judge === null}
disabled={false}
onClick={() => {
openPopup('flag');
}}
Expand Down