Skip to content

Commit

Permalink
alerts for server errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cecoeco committed Aug 5, 2024
1 parent 2186d2c commit 7cf7092
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/frontend/src/pages/flow_diagram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export default function FlowDiagram() {
};
}

const apiURL = "http://0.0.0.0:5050";
const apiURL = "https://prisma-jl.onrender.com";

async function getFlowDiagram() {
try {
Expand All @@ -377,19 +377,24 @@ export default function FlowDiagram() {
headers: { "Content-Type": "application/json" },
body: JSON.stringify(flowDiagramArguments()),
});

if (!response.ok) {
throw new Error(`Error fetching flow diagram: ${response.statusText}`);
}

const svgResponse = await response.json();
const svgData = new TextDecoder().decode(new Uint8Array(svgResponse.svg));
const container = document.querySelector(".flow-diagram-container");

if (container) {
container.innerHTML = svgData;
} else {
console.error("Container element not found");
alert("Error: Container element not found.");
}
} catch (error) {
console.error("Error fetching data:", error);
alert("Error: Unable to fetch flow diagram. Please try again later.");
}
}

Expand All @@ -404,20 +409,25 @@ export default function FlowDiagram() {
headers: { "Content-Type": "application/json" },
body: JSON.stringify(flowDiagramArguments()),
});

if (!response.ok) {
throw new Error(`Error fetching flow diagram: ${response.statusText}`);
}

const data = await response.json();
const flowDiagramBytes = data.flow_diagram;

if (!flowDiagramBytes) {
throw new Error("No binary data received from the server.");
}

const mimeTypeMap: { [key: string]: string } = {
png: "image/png",
svg: "image/svg+xml",
pdf: "application/pdf",
gv: "text/vnd.graphviz",
};

const mimeType = mimeTypeMap[saveFormat()];
const blob = new Blob([new Uint8Array(flowDiagramBytes)], { type: mimeType });
const url = URL.createObjectURL(blob);
Expand All @@ -430,6 +440,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.");
}
}

Expand Down

0 comments on commit 7cf7092

Please sign in to comment.