From 23bade4f261d41277010a22af55440212397d09c Mon Sep 17 00:00:00 2001 From: webofceco Date: Mon, 5 Aug 2024 19:33:06 -0400 Subject: [PATCH] better errors --- app/frontend/src/pages/checklist.tsx | 43 +++++++++++++++++-------- app/frontend/src/pages/flow_diagram.tsx | 26 +++++++++------ src/PRISMA.jl | 2 +- 3 files changed, 47 insertions(+), 24 deletions(-) diff --git a/app/frontend/src/pages/checklist.tsx b/app/frontend/src/pages/checklist.tsx index a7cb156..3aeb2c8 100644 --- a/app/frontend/src/pages/checklist.tsx +++ b/app/frontend/src/pages/checklist.tsx @@ -75,13 +75,21 @@ export default function Checklist() { const formData = new FormData(); formData.append("file", file()); try { - const response = await fetch("https://prisma-jl-api.onrender.com/checklist/generate", { - method: "POST", - body: formData, - }); + const response = await fetch( + "https://prisma-jl-api.onrender.com/checklist/generate", + { + method: "POST", + body: formData, + } + ); + if (!response.ok) { - throw new Error("Error submitting file"); + const errorData = await response.json(); + const errorMessage = `Error submitting file: ${errorData.error}`; + alert(errorMessage); + throw new Error(errorMessage); } + const result = await response.json(); const newFile = { selected: false, @@ -94,7 +102,7 @@ export default function Checklist() { } catch (error) { console.error("Error submitting file:", error); handleFileRemove(); - alert("File could not be sent to the server"); + alert(`File could not be sent to the server: ${error.message}`); } }; @@ -236,16 +244,22 @@ export default function Checklist() { checklist: file.checklist, })); try { - const response = await fetch("https://prisma-jl-api.onrender.com/checklist/export", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ checklists }), - }); + const response = await fetch( + "https://prisma-jl-api.onrender.com/checklist/export", + { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ checklists }), + } + ); + if (!response.ok) { - throw new Error("Failed to export files"); + const errorData = await response.json(); + const errorMessage = `Failed to export files: ${errorData.error}`; + alert(errorMessage); + throw new Error(errorMessage); } + const csvFiles = await response.json(); for (const [filename, csvContent] of Object.entries(csvFiles)) { const blob = new Blob([csvContent], { type: "text/csv" }); @@ -259,6 +273,7 @@ export default function Checklist() { } } catch (error) { console.error("Error exporting files:", error); + alert(`Error exporting files: ${error.message}`); } }; diff --git a/app/frontend/src/pages/flow_diagram.tsx b/app/frontend/src/pages/flow_diagram.tsx index ecac89b..e751e76 100644 --- a/app/frontend/src/pages/flow_diagram.tsx +++ b/app/frontend/src/pages/flow_diagram.tsx @@ -368,7 +368,7 @@ export default function FlowDiagram() { }; } - const apiURL = "https://prisma-jl.onrender.com"; + const apiURL = "https://prisma-jl-api.onrender.com"; async function getFlowDiagram() { try { @@ -379,7 +379,10 @@ export default function FlowDiagram() { }); if (!response.ok) { - throw new Error(`Error fetching flow diagram: ${response.statusText}`); + const errorData = await response.json(); + const errorMessage = `Error fetching flow diagram: ${errorData.error}`; + alert(errorMessage); + throw new Error(errorMessage); } const svgResponse = await response.json(); @@ -389,12 +392,12 @@ export default function FlowDiagram() { if (container) { container.innerHTML = svgData; } else { - console.error("Container element not found"); - alert("Error: Container element not found."); + console.error("Flow diagram container element not found"); + alert("Flow diagram container element not found."); } } catch (error) { - console.error("Error fetching data:", error); - alert("Error: Unable to fetch flow diagram. Please try again later."); + console.error("Error generating flow diagram:", error); + alert(`Error generating flow diagram: ${error.message}`); } } @@ -411,14 +414,19 @@ export default function FlowDiagram() { }); if (!response.ok) { - throw new Error(`Error fetching flow diagram: ${response.statusText}`); + const errorData = await response.json(); + const errorMessage = `Error fetching flow diagram: ${errorData.error}`; + alert(errorMessage); + throw new Error(errorMessage); } const data = await response.json(); const flowDiagramBytes = data.flow_diagram; if (!flowDiagramBytes) { - throw new Error("No binary data received from the server."); + const errorMessage = "No binary data received from the server."; + alert(errorMessage); + throw new Error(errorMessage); } const mimeTypeMap: { [key: string]: string } = { @@ -440,7 +448,7 @@ export default function FlowDiagram() { URL.revokeObjectURL(url); } catch (error) { console.error("Error downloading flow diagram:", error); - alert("Error: Unable to download flow diagram. Please try again later."); + alert(`Error downloading flow diagram: ${error.message}`); } } diff --git a/src/PRISMA.jl b/src/PRISMA.jl index fb2b570..dbfb617 100644 --- a/src/PRISMA.jl +++ b/src/PRISMA.jl @@ -8,7 +8,7 @@ Julia package for generating checklists and flow diagrams based on the [2020 **P - `checklist_df`: returns an empty PRISMA checklist as the type `DataFrame` - `checklist`: returns a completed PRISMA checklist as the type `Checklist` - `flow_diagram_df`: returns the `DataFrame` that is used to create the flow diagram -- `flow_diagram`: returns a completed PRISMA flow diagram as the type `FlowDiagram` +- `flow_diagram`: returns a PRISMA flow diagram as the type `FlowDiagram` - `flow_diagram_save`: saves a `FlowDiagram` to any file format supported by `Graphviz_jll` ## Types