hcengineering/platform · error

Internal server error

Error message

Internal server error

What it means

Generic catch-all in handlePolarWebhook: any non-signature error while processing a Polar webhook (JSON parse failure of a validly-signed event, DB errors, handler exceptions) yields HTTP 500 'Internal server error'.

Source

Thrown at services/payment/pod-payment/src/providers/polar/webhook.ts:77

          ctx.error('Failed to process Polar webhook event', { event, err })
        })
        break
      default:
    }

    res.status(202).json({ received: true })
  } catch (err) {
    // Check if it's a validation error by class name
    const isValidationError = err instanceof WebhookVerificationError

    if (isValidationError) {
      ctx.error('Invalid Polar webhook signature', { err })
      res.status(403).json({ error: 'Invalid signature' })
      return
    }

    ctx.error('Failed to process Polar webhook', { err })
    res.status(500).json({ error: 'Internal server error' })
  }
}

/**
 * Handle subscription.created/updated/active
 */
async function handleSubscriptionUpdated (
  ctx: MeasureContext,
  accountsUrl: string,
  serviceToken: string,
  event: any
): Promise<void> {
  const subscription = event.data ?? event
  if (subscription == null) {
    ctx.error('Missing subscription data', { event })
    throw new Error('Missing subscription data')
  }

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Read the server logs (ctx.error 'Failed to process Polar webhook') for the underlying err and fix that root cause
  2. Replay the failed webhook from the Polar dashboard after fixing
  3. Add handling for unrecognized/unsupported event types before processing
  4. Check database health / migrations if handlers persist subscription state

Example fix

// before
default:
  throw new Error(`Unhandled event ${event.type}`)
// after
default:
  ctx.warn('Unhandled Polar event type', { type: event.type })
  res.status(200).json({ received: true })
  return
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await handleEvent(event)
} catch (err) {
  ctx.error('Failed to process Polar webhook', { err })
  res.status(500).json({ error: 'Internal server error' })
}

Prevention

When it happens

Trigger: validateEvent throws a non-WebhookVerificationError (e.g. malformed JSON inside a signed body); a subscription event handler throws (DB down, unknown price id, unhandled shape); unexpected runtime exception in the switch dispatch.

Common situations: Polar sends a new event type the handler's switch doesn't recognize and downstream code assumes a shape that's absent; database migration drift; transient DB connectivity loss during event processing.

Understand the failure class

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/48f449bbeaeae80c. Report an issue: GitHub.