From fa9a83a4271f780ee87851348b2ff159ec3ff382 Mon Sep 17 00:00:00 2001 From: Quaternions <krakow20@gmail.com> Date: Mon, 24 Mar 2025 14:59:33 -0700 Subject: [PATCH 1/3] web: throw error on failure status --- .../[submissionId]/_reviewButtons.tsx | 25 ++++++++++++++----- web/src/app/submit/page.tsx | 8 ++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/web/src/app/submissions/[submissionId]/_reviewButtons.tsx b/web/src/app/submissions/[submissionId]/_reviewButtons.tsx index a038d9e..85e6601 100644 --- a/web/src/app/submissions/[submissionId]/_reviewButtons.tsx +++ b/web/src/app/submissions/[submissionId]/_reviewButtons.tsx @@ -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) { + let 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 submitting data:", error); + } } function ReviewButton(props: ReviewButton) { diff --git a/web/src/app/submit/page.tsx b/web/src/app/submit/page.tsx index c562ad3..870cfd1 100644 --- a/web/src/app/submit/page.tsx +++ b/web/src/app/submit/page.tsx @@ -51,6 +51,14 @@ export default function SubmissionInfoPage() { body: JSON.stringify(payload), }); + // Check if the HTTP request was successful + if (!response.ok) { + let 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(); -- 2.47.1 From 298f3d9b8eb625a6213e8f0e488d6b7c493f3290 Mon Sep 17 00:00:00 2001 From: rhpidfyre <brandon@rhpidfyre.io> Date: Mon, 24 Mar 2025 18:45:07 -0400 Subject: [PATCH 2/3] Change these to `const` so the code builds --- web/src/app/submissions/[submissionId]/_reviewButtons.tsx | 2 +- web/src/app/submit/page.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/app/submissions/[submissionId]/_reviewButtons.tsx b/web/src/app/submissions/[submissionId]/_reviewButtons.tsx index 85e6601..2b9f049 100644 --- a/web/src/app/submissions/[submissionId]/_reviewButtons.tsx +++ b/web/src/app/submissions/[submissionId]/_reviewButtons.tsx @@ -25,7 +25,7 @@ async function ReviewButtonClicked(action: Action, submissionId: string) { }); // Check if the HTTP request was successful if (!response.ok) { - let errorDetails = await response.text(); + const errorDetails = await response.text(); // Throw an error with detailed information throw new Error(`HTTP error! status: ${response.status}, details: ${errorDetails}`); diff --git a/web/src/app/submit/page.tsx b/web/src/app/submit/page.tsx index 870cfd1..6f3c1b7 100644 --- a/web/src/app/submit/page.tsx +++ b/web/src/app/submit/page.tsx @@ -53,7 +53,7 @@ export default function SubmissionInfoPage() { // Check if the HTTP request was successful if (!response.ok) { - let errorDetails = await response.text(); + const errorDetails = await response.text(); // Throw an error with detailed information throw new Error(`HTTP error! status: ${response.status}, details: ${errorDetails}`); -- 2.47.1 From a4dc625bd870cd5b296256e3fa3e2e1106ad51c3 Mon Sep 17 00:00:00 2001 From: Quaternions <krakow20@gmail.com> Date: Mon, 24 Mar 2025 15:51:03 -0700 Subject: [PATCH 3/3] web: change error message --- web/src/app/submissions/[submissionId]/_reviewButtons.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/app/submissions/[submissionId]/_reviewButtons.tsx b/web/src/app/submissions/[submissionId]/_reviewButtons.tsx index 2b9f049..fd51d73 100644 --- a/web/src/app/submissions/[submissionId]/_reviewButtons.tsx +++ b/web/src/app/submissions/[submissionId]/_reviewButtons.tsx @@ -33,7 +33,7 @@ async function ReviewButtonClicked(action: Action, submissionId: string) { window.location.reload(); } catch (error) { - console.error("Error submitting data:", error); + console.error("Error updating submission status:", error); } } -- 2.47.1