Phase 6 complete

This commit is contained in:
Joey Yakimowich-Payne 2026-01-13 16:52:57 -07:00
commit 3a22b42492
No known key found for this signature in database
GPG key ID: 6BFE655FA5ABD1E1
11 changed files with 735 additions and 103 deletions

View file

@ -36,17 +36,29 @@ export const useAuthenticatedFetch = () => {
const authFetch = useCallback(
async (path: string, options: RequestInit = {}): Promise<Response> => {
if (!navigator.onLine) {
throw new Error('You appear to be offline. Please check your connection.');
}
const token = await ensureValidToken();
const url = path.startsWith('http') ? path : `${API_URL}${path}`;
const response = await fetch(url, {
...options,
headers: {
...options.headers,
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
});
let response: Response;
try {
response = await fetch(url, {
...options,
headers: {
...options.headers,
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
});
} catch (err) {
if (!navigator.onLine) {
throw new Error('You appear to be offline. Please check your connection.');
}
throw new Error('Network error. Please try again.');
}
if (response.status === 401) {
try {
@ -66,6 +78,10 @@ export const useAuthenticatedFetch = () => {
}
throw new Error('Session expired, redirecting to login');
}
if (response.status >= 500) {
throw new Error('Server error. Please try again later.');
}
return response;
},