diff --git a/apps/storefront/lib/ai/tools.ts b/apps/storefront/lib/ai/tools.ts index 9e2609e..91cfc2e 100644 --- a/apps/storefront/lib/ai/tools.ts +++ b/apps/storefront/lib/ai/tools.ts @@ -157,10 +157,15 @@ export function createTools(customerId: string, _conversationId?: string) { }; } - // selectPayment throws for orders that predate the payments launch — - // the demo's planted failure. Nothing catches it here on purpose: the - // AI SDK turns the rejection into a tool-error result. - const payment = await db.selectPayment(orderId); + let payment; + try { + payment = await db.selectPayment(orderId); + } catch (err) { + return { + refunded: false as const, + reason: err instanceof Error ? err.message : String(err), + }; + } const refund = await issueRefund({ chargeId: payment.chargeId, amount: order.total.amount,