diff --git a/src/lib/api.js b/src/lib/api.js index e3ed34f..206fb1d 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -46,6 +46,12 @@ export const anthropicApi = { throw new Error(`API Error: ${response.status} ${response.statusText} - ${JSON.stringify(errData)}`); } + // Detect auth portal session expiry: the portal returns HTML instead of JSON + const contentType = response.headers.get('content-type') || ''; + if (!contentType.includes('application/json')) { + throw new Error('Your session has expired. Please refresh the page and log in again.'); + } + const data = await response.json(); return data.content[0].text; } catch (error) { diff --git a/src/lib/pb.js b/src/lib/pb.js index 03fa049..6c82e7e 100644 --- a/src/lib/pb.js +++ b/src/lib/pb.js @@ -4,3 +4,13 @@ const pbUrl = import.meta.env.VITE_PB_URL || (typeof window !== 'undefined' ? window.location.origin : 'http://localhost:8090'); export const pb = new PocketBase(pbUrl); + +// Detect auth portal session expiry: the portal returns HTML instead of JSON. +// This prevents cryptic "Unexpected token '<'" errors when the session expires. +pb.afterSend = function (response, data) { + const contentType = response.headers.get('content-type') || ''; + if (contentType.includes('text/html')) { + throw new Error('Your session has expired. Please refresh the page and log in again.'); + } + return data; +};