Skip to content

Commit

Permalink
fix issue #24 with catching error stage
Browse files Browse the repository at this point in the history
  • Loading branch information
giahp committed Nov 18, 2024
1 parent e07bd2f commit 46e680e
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/pages/profiles/ProfilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function ProfilePage() {

const currentUser = useCurrentUser();
const { id } = useParams();
const [error, setError] = useState(null);

const { setProfileData, handleFollow, handleUnfollow } = useSetProfileData();
const { pageProfile } = useProfileData();
Expand Down Expand Up @@ -61,7 +62,12 @@ function ProfilePage() {
setProfilePosts(profilePosts);
setHasLoaded(true);
} catch (err) {
console.log(err);
setHasLoaded(true);
if (err.response?.status === 404) {
setError("Profile not found!"); // Set the error message
} else {
console.log(err);
}
}
};
fetchData();
Expand Down Expand Up @@ -157,10 +163,14 @@ function ProfilePage() {
<PopularProfiles mobile />
<Container className={appStyles.Content}>
{hasLoaded ? (
<>
{mainProfile}
{mainProfilePosts}
</>
error ? (
<p>{error}</p> // Display error message
) : (
<>
{mainProfile}
{mainProfilePosts}
</>
)
) : (
<Asset spinner />
)}
Expand Down

0 comments on commit 46e680e

Please sign in to comment.