Skip to content
Back to snapcart-api report
ReliabilityMedium

Missing Error Handling

src/services/payment.ts:73

What's going on

The payment capture call is not wrapped in a try/catch and its failure is treated as success by the caller, so charge failures can silently mark orders as paid.

Why it matters

Payment flows that ignore errors produce real financial damage — chargebacks, duplicate charges, and inconsistent order state.

src/services/payment.ts:73

Recommended Fix

Replace the inline query with a parameterized statement and validate the id before it ever reaches the database. A regression test is generated alongside the patch.

Before
1export async function capture(orderId: string) {2  const intent = await paymentGateway.authorize(orderId);3  const charge = await paymentGateway.capture(intent.id); // may throw4  return { ok: true, charge };5}
After
1export async function capture(orderId: string) {2  try {3    const intent = await paymentGateway.authorize(orderId);4    const charge = await paymentGateway.capture(intent.id);5    return { ok: true, charge };6  } catch (err) {7    await markChargeFailed(orderId, err);8    return { ok: false };9  }10}
  1. Uploaddone
  2. Analyzedone
  3. Finddone
  4. Explainactive
  5. Fixupcoming
  6. Testupcoming
  7. Verifyupcoming