Improve error handling, automatically renew access token

This commit is contained in:
2025-11-06 20:47:08 +02:00
parent bb3900d23b
commit 65794be998
7 changed files with 374 additions and 175 deletions

View File

@@ -1,4 +1,3 @@
import type { Route } from "../+types/root";
import { useState, useEffect, type FormEventHandler } from "react";
@@ -12,6 +11,7 @@ import { API } from "../api/api";
import { useNavigate } from "react-router";
import type { PaginatedResponse } from "~/types/PaginatedResponse";
import Loading from "~/components/Loading";
import { getApiErrorMessage } from "~/context/AuthContext";
interface PostCardProps {
post: Post;
@@ -113,8 +113,12 @@ export default function Posts() {
useEffect(() => {
const fetchData = async () => {
const data = await API.fetchPosts(currentPage, searchQuery);
setPaginatedData(data);
try {
const data = await API.fetchPosts(currentPage, searchQuery);
setPaginatedData(data);
} catch (err: any) {
alert(`Failed to fetch posts: ${getApiErrorMessage(err)}`);
}
}
fetchData();
}, [currentPage, searchQuery]);