Skip to content

fix: add type-safe env var checks and improve FAILED transaction handling in webhook - #31

Open
consumeobeydie wants to merge 1 commit into
circlefin:masterfrom
consumeobeydie:fix/webhook-type-safety
Open

fix: add type-safe env var checks and improve FAILED transaction handling in webhook#31
consumeobeydie wants to merge 1 commit into
circlefin:masterfrom
consumeobeydie:fix/webhook-type-safety

Conversation

@consumeobeydie

Copy link
Copy Markdown

Problem

app/api/circle/webhook/route.ts has two issues:

  1. TypeScript type error: createClient() is called with process.env.NEXT_PUBLIC_SUPABASE_URL and process.env.SUPABASE_SERVICE_ROLE_KEY which are typed as string | undefined. This causes a TypeScript compile error since createClient expects string.

  2. Silent failure on FAILED transactions: When a transaction fails on-chain, the handler only logs to console and skips any DB update. If the webhook fires and the transaction was never recorded as failed, there is no audit trail.

  3. Silent failure after max retries: If a transaction cannot be matched after 10 attempts, the webhook silently returns 200 with no indication of the failure.

Fix

  • Added runtime env var validation with a descriptive error message
  • Extracted supabaseUrl and supabaseServiceRoleKey into typed variables so TypeScript is satisfied
  • Added updated_at timestamp update for FAILED transactions for audit trail
  • Added console.error log when transaction cannot be matched after MAX_ATTEMPTS

Changes

  • app/api/circle/webhook/route.ts — type-safe env vars, FAILED transaction audit update, unmatched transaction log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant