See the best posts from any Bluesky account
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Report server errors to PostHog via captureException in exception handler

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+11
+11
app/exceptions/handler.ts
··· 1 1 import app from '@adonisjs/core/services/app' 2 2 import { type HttpContext, ExceptionHandler } from '@adonisjs/core/http' 3 3 import type { StatusPageRange, StatusPageRenderer } from '@adonisjs/core/types/http' 4 + import { getPostHogClient } from '#services/posthog' 4 5 5 6 export default class HttpExceptionHandler extends ExceptionHandler { 6 7 /** ··· 44 45 * @note You should not attempt to send a response from this method. 45 46 */ 46 47 async report(error: unknown, ctx: HttpContext) { 48 + const posthog = getPostHogClient() 49 + if (posthog && this.shouldReport(error as any)) { 50 + const distinctId = ctx.auth?.user?.did ?? 'anonymous' 51 + posthog.captureException(error as Error, distinctId, { 52 + $current_url: ctx.request.url(), 53 + http_method: ctx.request.method(), 54 + route: ctx.route?.pattern, 55 + }) 56 + } 57 + 47 58 return super.report(error, ctx) 48 59 } 49 60 }