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 submissionId: string
} }
function ReviewButtonClicked(action: Action, submissionId: string) { async function ReviewButtonClicked(action: Action, submissionId: string) {
fetch(`/api/submissions/${submissionId}/status/${action}`, { try {
const response = await fetch(`/api/submissions/${submissionId}/status/${action}`, {
method: "POST", method: "POST",
headers: { headers: {
"Content-type": "application/json", "Content-type": "application/json",
} }
}).then(() => { window.location.reload(); }) });
// 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}`);
}
window.location.reload();
} catch (error) {
console.error("Error updating submission status:", error);
}
} }
function ReviewButton(props: ReviewButton) { function ReviewButton(props: ReviewButton) {

@ -51,6 +51,14 @@ export default function SubmissionInfoPage() {
body: JSON.stringify(payload), 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 // Allow any HTTP status
const id_response:IdResponse = await response.json(); const id_response:IdResponse = await response.json();