🐛 fix(tabsContext.tsx): add try-catch block to handle JSON parsing errors

🐛 fix(API/index.ts): remove duplicate forward slash in API routes
The try-catch block was added to handle JSON parsing errors that may occur when parsing the cookieObject. This ensures that the application does not crash when such errors occur.

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.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-08 17:51:06 -03:00
commit 7ed19c739b
2 changed files with 11 additions and 10 deletions

View file

@ -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]);

View file

@ -4,23 +4,23 @@ import axios, { AxiosResponse } from "axios";
import { FlowType } from "../../types/flow";
export async function getAll(): Promise<AxiosResponse<APIObjectType>> {
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<AxiosResponse<errorsTypeAPI>> {
return await axios.post("api/v1/validate/code", { code });
return await axios.post("/validate/code", { code });
}
export async function checkPrompt(
template: string
): Promise<AxiosResponse<PromptTypeAPI>> {
return await axios.post("api/v1/validate/prompt", { template });
return await axios.post("/validate/prompt", { template });
}
export async function getExamples(): Promise<FlowType[]> {
@ -37,7 +37,5 @@ export async function getExamples(): Promise<FlowType[]> {
return contentResponse.data;
});
const contents = await Promise.all(contentsPromises);
return contents;
return await Promise.all(contentsPromises);
}