Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions apps/storefront/lib/ai/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading