Skip to content

Commit

Permalink
error showing in new post
Browse files Browse the repository at this point in the history
  • Loading branch information
VaibhavArora314 committed Jun 1, 2024
1 parent 0181d0c commit 3229c38
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion backend/src/routes/post/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
});
}

Expand Down
32 changes: 13 additions & 19 deletions frontend/src/pages/NewPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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 (
<div className="p-6 text-white max-w-screen-xl mx-auto">
<h2 className="text-2xl font-semibold mb-4">Create New Post</h2>
<p className="mt-4">{error.message}</p>
<p className="mt-4">{errorMessage}</p>
<form onSubmit={handleSubmit} className="space-y-4">
<div>
<label htmlFor="title" className="block text-sm font-medium">
Expand Down

0 comments on commit 3229c38

Please sign in to comment.