fix: handle FastAPI validation error objects in tool workshop
- Add extractErrorMessage helper to safely stringify validation error arrays - Apply to tool type, config, and folder save handlers - Fixes React error #31 when rendering error objects directly in JSX Closes: redesign-tool-workshop
This commit is contained in:
@@ -186,6 +186,16 @@ export const ToolWorkshopPage = () => {
|
|||||||
setShowFolderForm(false);
|
setShowFolderForm(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const extractErrorMessage = (err: unknown): string => {
|
||||||
|
const axiosError = err as { response?: { data?: { detail?: string | Array<{msg?: string}> } } };
|
||||||
|
const detail = axiosError?.response?.data?.detail;
|
||||||
|
if (typeof detail === 'string') return detail;
|
||||||
|
if (Array.isArray(detail)) {
|
||||||
|
return detail.map(d => typeof d === 'string' ? d : d.msg || JSON.stringify(d)).join(', ');
|
||||||
|
}
|
||||||
|
return "Failed to save";
|
||||||
|
};
|
||||||
|
|
||||||
const handleToolTypeSubmit = async (e: React.FormEvent) => {
|
const handleToolTypeSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setToolTypeError(null);
|
setToolTypeError(null);
|
||||||
@@ -259,8 +269,7 @@ export const ToolWorkshopPage = () => {
|
|||||||
}
|
}
|
||||||
await loadData();
|
await loadData();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const axiosError = err as { response?: { data?: { detail?: string } } };
|
setToolTypeError(extractErrorMessage(err));
|
||||||
setToolTypeError(axiosError?.response?.data?.detail || "Failed to save tool type");
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -372,8 +381,7 @@ export const ToolWorkshopPage = () => {
|
|||||||
resetConfigForm();
|
resetConfigForm();
|
||||||
await loadData();
|
await loadData();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const axiosError = err as { response?: { data?: { detail?: string } } };
|
setConfigError(extractErrorMessage(err));
|
||||||
setConfigError(axiosError?.response?.data?.detail || "Failed to save config");
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -456,8 +464,7 @@ export const ToolWorkshopPage = () => {
|
|||||||
resetFolderForm();
|
resetFolderForm();
|
||||||
await loadData();
|
await loadData();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const axiosError = err as { response?: { data?: { detail?: string } } };
|
setFolderError(extractErrorMessage(err));
|
||||||
setFolderError(axiosError?.response?.data?.detail || "Failed to save folder");
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user