web: throw error on failure status ()

Thanks to ai for knowing javascript

Co-authored-by: rhpidfyre <brandon@rhpidfyre.io>
Reviewed-on: 
Co-authored-by: Quaternions <krakow20@gmail.com>
Co-committed-by: Quaternions <krakow20@gmail.com>
This commit is contained in:
Quaternions 2025-03-24 23:03:53 +00:00 committed by Quaternions
parent 08a4e913a9
commit 3da4023466
2 changed files with 27 additions and 6 deletions
web/src/app
submissions/[submissionId]
submit

@ -15,13 +15,26 @@ interface ReviewId {
submissionId: string
}
function ReviewButtonClicked(action: Action, submissionId: string) {
fetch(`/api/submissions/${submissionId}/status/${action}`, {
method: "POST",
headers: {
"Content-type": "application/json",
async function ReviewButtonClicked(action: Action, submissionId: string) {
try {
const response = await fetch(`/api/submissions/${submissionId}/status/${action}`, {
method: "POST",
headers: {
"Content-type": "application/json",
}
});
// Check if the HTTP request was successful
if (!response.ok) {
const errorDetails = await response.text();
// Throw an error with detailed information
throw new Error(`HTTP error! status: ${response.status}, details: ${errorDetails}`);
}
}).then(() => { window.location.reload(); })
window.location.reload();
} catch (error) {
console.error("Error updating submission status:", error);
}
}
function ReviewButton(props: ReviewButton) {

@ -51,6 +51,14 @@ export default function SubmissionInfoPage() {
body: JSON.stringify(payload),
});
// Check if the HTTP request was successful
if (!response.ok) {
const errorDetails = await response.text();
// Throw an error with detailed information
throw new Error(`HTTP error! status: ${response.status}, details: ${errorDetails}`);
}
// Allow any HTTP status
const id_response:IdResponse = await response.json();