web: throw error on failure status (#16)
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 is contained in:
parent
08a4e913a9
commit
3da4023466
web/src/app
@ -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 {
|
||||||
method: "POST",
|
const response = await fetch(`/api/submissions/${submissionId}/status/${action}`, {
|
||||||
headers: {
|
method: "POST",
|
||||||
"Content-type": "application/json",
|
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) {
|
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();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user