diff --git a/backend/src/routes/post/controller.ts b/backend/src/routes/post/controller.ts index 09eca147..fd8ef30e 100644 --- a/backend/src/routes/post/controller.ts +++ b/backend/src/routes/post/controller.ts @@ -40,7 +40,7 @@ export const createPostController = async ( formattedError[e.path[0]] = e.message; }); return res.status(411).json({ - error: { ...formattedError, message: "" }, + error: { ...formattedError, message: "Invalid Inputs" }, }); } diff --git a/frontend/src/pages/NewPost.tsx b/frontend/src/pages/NewPost.tsx index e37fcd97..acc9da42 100644 --- a/frontend/src/pages/NewPost.tsx +++ b/frontend/src/pages/NewPost.tsx @@ -12,13 +12,14 @@ const NewPost = () => { const [tagInput, setTagInput] = useState(""); const token = useRecoilValue(tokenState); const navigate = useNavigate(); - const [error, setError] = useState({ - title: "", - description: "", - codeSnippet: "", - tags: "", - message: "", - }); + // const [error, setError] = useState({ + // title: "", + // description: "", + // codeSnippet: "", + // tags: "", + // message: "", + // }); + const [errorMessage, setErrorMessage] = useState(""); const handleAddTag = () => { if (tagInput.length > 0 && !tags.includes(tagInput)) { @@ -56,24 +57,17 @@ const NewPost = () => { message: string; }; }>; - if (axiosError.response && axiosError.response.data) { - setError((e) => { - e.message = axiosError?.response?.data.error.message || "An unexpected error occurred."; - return e; - }); - } else { - setError((e) => { - e.message = "An unexpected error occurred."; - return e; - }); - } + setErrorMessage( + axiosError?.response?.data?.error.message || + "An unexpected error occurred." + ); } }; return (
{error.message}
+{errorMessage}