From 7ed19c739bc03cb618cdb90eb3934003ceff908d Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 8 Jun 2023 17:51:06 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(tabsContext.tsx):=20add=20tr?= =?UTF-8?q?y-catch=20block=20to=20handle=20JSON=20parsing=20errors=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(API/index.ts):=20remove=20duplicate=20forwar?= =?UTF-8?q?d=20slash=20in=20API=20routes=20The=20try-catch=20block=20was?= =?UTF-8?q?=20added=20to=20handle=20JSON=20parsing=20errors=20that=20may?= =?UTF-8?q?=20occur=20when=20parsing=20the=20cookieObject.=20This=20ensure?= =?UTF-8?q?s=20that=20the=20application=20does=20not=20crash=20when=20such?= =?UTF-8?q?=20errors=20occur.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The duplicate forward slash in the API routes was removed to ensure that the routes are correctly formed and the API requests are sent to the correct endpoints. --- src/frontend/src/contexts/tabsContext.tsx | 9 ++++++--- src/frontend/src/controllers/API/index.ts | 12 +++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx index fe53e277e..1907a5590 100644 --- a/src/frontend/src/contexts/tabsContext.tsx +++ b/src/frontend/src/contexts/tabsContext.tsx @@ -89,10 +89,11 @@ export function TabsProvider({ children }: { children: ReactNode }) { let cookie = window.localStorage.getItem("tabsData"); if (cookie && Object.keys(templates).length > 0) { let cookieObject: LangFlowState = JSON.parse(cookie); + try { cookieObject.flows.forEach((flow) => { - if (!flow.data) { - return; - } + if (!flow.data) { + return; + } flow.data.edges.forEach((edge) => { edge.className = ""; edge.style = { stroke: "#555555" }; @@ -126,6 +127,8 @@ export function TabsProvider({ children }: { children: ReactNode }) { setTabIndex(cookieObject.tabIndex); setFlows(cookieObject.flows); setId(cookieObject.id); + } catch (e) { + console.log(e); } } }, [templates]); diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index dbac43dbd..ffa9eef72 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -4,23 +4,23 @@ import axios, { AxiosResponse } from "axios"; import { FlowType } from "../../types/flow"; export async function getAll(): Promise> { - return await axios.get(`api/v1/all`); + return await axios.get(`/all`); } export async function sendAll(data: sendAllProps) { - return await axios.post(`api/v1//predict`, data); + return await axios.post(`/predict`, data); } export async function checkCode( code: string ): Promise> { - return await axios.post("api/v1/validate/code", { code }); + return await axios.post("/validate/code", { code }); } export async function checkPrompt( template: string ): Promise> { - return await axios.post("api/v1/validate/prompt", { template }); + return await axios.post("/validate/prompt", { template }); } export async function getExamples(): Promise { @@ -37,7 +37,5 @@ export async function getExamples(): Promise { return contentResponse.data; }); - const contents = await Promise.all(contentsPromises); - - return contents; + return await Promise.all(contentsPromises); }