{"record":{"id":"48f449bbeaeae80c","repo":"hcengineering/platform","slug":"internal-server-error-48f449","errorCode":null,"errorMessage":"Internal server error","messagePattern":"Internal server error","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"services/payment/pod-payment/src/providers/polar/webhook.ts","lineNumber":77,"sourceCode":"          ctx.error('Failed to process Polar webhook event', { event, err })\n        })\n        break\n      default:\n    }\n\n    res.status(202).json({ received: true })\n  } catch (err) {\n    // Check if it's a validation error by class name\n    const isValidationError = err instanceof WebhookVerificationError\n\n    if (isValidationError) {\n      ctx.error('Invalid Polar webhook signature', { err })\n      res.status(403).json({ error: 'Invalid signature' })\n      return\n    }\n\n    ctx.error('Failed to process Polar webhook', { err })\n    res.status(500).json({ error: 'Internal server error' })\n  }\n}\n\n/**\n * Handle subscription.created/updated/active\n */\nasync function handleSubscriptionUpdated (\n  ctx: MeasureContext,\n  accountsUrl: string,\n  serviceToken: string,\n  event: any\n): Promise<void> {\n  const subscription = event.data ?? event\n  if (subscription == null) {\n    ctx.error('Missing subscription data', { event })\n    throw new Error('Missing subscription data')\n  }\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/services/payment/pod-payment/src/providers/polar/webhook.ts#L59-L95","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the server logs (ctx.error 'Failed to process Polar webhook') for the underlying err and fix that root cause","Replay the failed webhook from the Polar dashboard after fixing","Add handling for unrecognized/unsupported event types before processing","Check database health / migrations if handlers persist subscription state"],"exampleFix":"// before\ndefault:\n  throw new Error(`Unhandled event ${event.type}`)\n// after\ndefault:\n  ctx.warn('Unhandled Polar event type', { type: event.type })\n  res.status(200).json({ received: true })\n  return","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await handleEvent(event)\n} catch (err) {\n  ctx.error('Failed to process Polar webhook', { err })\n  res.status(500).json({ error: 'Internal server error' })\n}","preventionTips":["Handle unknown event types gracefully (200 + warn) so Polar doesn't retry forever","Make event handlers idempotent for replays","Monitor ctx.error logs for root causes","Keep DB migrations and handler assumptions in sync"],"tags":["webhook","unhandled-exception","http-500"],"backgroundTag":"webhook-handler-crash","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}