Ignore:
Timestamp:
01/26/26 20:19:20 (6 months ago)
Author:
Dimitar Arsov <dimitararsov04@…>
Branches:
main
Children:
d47e225
Parents:
fd81a18
Message:

add Global exception handler

File:
1 moved

Legend:

Unmodified
Added
Removed
  • frontend/src/components/userProfile/UserDetailView.tsx

    rfd81a18 ra3ae097  
    4848  const navigate = useNavigate();
    4949  const [user, setUser] = useState<User | null>(null);
     50  const [error, setError] = useState<string | null>(null);
    5051
    5152  useEffect(() => {
    5253    const fetchUser = async () => {
    53       console.log(userId);
    54       const response = await fetch(`http://localhost:8080/users/${userId}`);
    55       const data = await response.json();
    56       console.log("Fetched user data:", data);
    57       setUser(data);
     54      setError(null);
     55      try {
     56        const response = await fetch(`http://localhost:8080/users/${userId}`);
     57
     58        if (!response.ok) {
     59          const errorData = await response.json();
     60          throw new Error(errorData.error || "Failed to fetch user");
     61        }
     62
     63        const data = await response.json();
     64        setUser(data);
     65      } catch (err: any) {
     66        setError(err.message);
     67      }
    5868    };
    5969    fetchUser();
    6070  }, [userId]);
     71
     72  if (error) {
     73    return (
     74      <div className="p-6 bg-red-50 border border-red-200 text-red-700 rounded-lg">
     75        <h2 className="font-bold">Error</h2>
     76        <p>{error}</p>
     77      </div>
     78    );
     79  }
    6180
    6281  if (!user) return <div className="p-6">Loading...</div>;
     
    7291
    7392      <div className="bg-white shadow-lg rounded-lg p-8">
    74         {/* Profile Header */}
    7593        <div className="flex items-start gap-6 mb-8">
    76           {/* Profile Photo */}
    7794          <div className="shrink-0">
    7895            <div className="w-32 h-32 rounded-full bg-linear-to-br from-blue-400 to-purple-500 flex items-center justify-center text-white text-4xl font-bold shadow-lg">
     
    8198          </div>
    8299
    83           {/* User Info */}
    84100          <div className="flex-1">
    85101            <h1 className="text-4xl font-bold mb-2">{user.fullName}</h1>
     
    88104            </span>
    89105
    90             {/* Followers/Following Stats */}
    91106            <div className="flex gap-6 mb-4 text-gray-700">
    92107              <div className="flex flex-col">
Note: See TracChangeset for help on using the changeset viewer.