Files
Compass/web/pages/api/sentry-example-api.ts
MartinBraquet b59b0edd4a Add sentry
2026-03-02 18:06:04 +01:00

22 lines
676 B
TypeScript

import * as Sentry from '@sentry/nextjs'
import type {NextApiRequest, NextApiResponse} from 'next'
// Custom error class for Sentry testing
class SentryExampleAPIError extends Error {
constructor(message: string | undefined) {
super(message)
this.name = 'SentryExampleAPIError'
}
}
type Response = {
name: string
}
// A faulty API route to test Sentry's error monitoring
export default function handler(_req: NextApiRequest, _res: NextApiResponse<Response>) {
Sentry.logger.info('Sentry example API called')
throw new SentryExampleAPIError('This error is raised on the backend called by the example page.')
// res.status(200).json({name: 'John Doe'})
}