diff --git a/src/lib/ai.ts b/src/lib/ai.ts index 4e2f2b67f..640e7a695 100644 --- a/src/lib/ai.ts +++ b/src/lib/ai.ts @@ -395,6 +395,14 @@ export async function fetchWithAuthHandling( if (!response.ok) { const data = await response.json(); if (data?.errors) { + if (data?.type && data?.type === 'ai_tutor_limit_exceeded') { + window?.fireEvent?.({ + action: 'tutor_credit_limit', + category: 'ai_tutor', + label: 'Tutor Credit Limit Exceeded', + }); + } + throw new FetchError(response.status, data.message); } else { throw new Error('An unexpected error occurred'); diff --git a/src/lib/query-http.ts b/src/lib/query-http.ts index aaa8016b4..38b47f622 100644 --- a/src/lib/query-http.ts +++ b/src/lib/query-http.ts @@ -86,6 +86,14 @@ export async function httpCall( if (!response.ok) { if (data.errors) { + if (data?.type && data?.type === 'ai_tutor_limit_exceeded') { + window?.fireEvent?.({ + action: 'tutor_credit_limit', + category: 'ai_tutor', + label: 'Tutor Credit Limit Exceeded', + }); + } + throw new FetchError(response?.status, data.message); } else if (data.message) { throw new FetchError(response?.status, data.message);