web: throw error on failure status (#16)
All checks were successful
continuous-integration/drone/push Build is passing

Thanks to ai for knowing javascript

Co-authored-by: rhpidfyre <brandon@rhpidfyre.io>
Reviewed-on: #16
Co-authored-by: Quaternions <krakow20@gmail.com>
Co-committed-by: Quaternions <krakow20@gmail.com>
This commit was merged in pull request #16.
This commit is contained in:
2025-03-24 23:03:53 +00:00
committed by Quaternions
parent 08a4e913a9
commit 3da4023466
2 changed files with 27 additions and 6 deletions

View File

@@ -15,13 +15,26 @@ interface ReviewId {
submissionId: string
}
function ReviewButtonClicked(action: Action, submissionId: string) {
fetch(`/api/submissions/${submissionId}/status/${action}`, {
async function ReviewButtonClicked(action: Action, submissionId: string) {
try {
const response = await fetch(`/api/submissions/${submissionId}/status/${action}`, {
method: "POST",
headers: {
"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) {

View File

@@ -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();