Handle errors and limits
Every error has a code and a message written for your users.
errors.js
try {
const reply = await charge.ai.chat(text)
out.textContent = reply.text
} catch (e) {
if (e.code === 'cancelled') return // the user closed a sheet
out.textContent = e.message // already written for the user
} cancelled: the user closed the sign-in or payment sheet. Do nothing.daily_cap: your app reached the daily limit this user set. ChargeMyAI already offered them their account.paused: the user paused spending in all apps.popup_blocked: the browser or a preview frame blocked the sign-in window.device_unavailable: you asked formode: 'device'and the device can't answer.upstream_unavailable: no model answered. The user was not charged.
Read next
Still stuck? Talk to us and we'll help.