a fun bot for the hc slack
at main 620 B view raw
1import * as Sentry from "@sentry/bun"; 2 3export interface ApiError { 4 message: string; 5 status: number; 6} 7 8export function handleApiError(error: unknown, context: string): Response { 9 if (error instanceof Error) { 10 Sentry.captureException(error, { 11 extra: { context }, 12 tags: { type: "api_error" }, 13 }); 14 15 return new Response(JSON.stringify({ error: error.message }), { 16 status: 500, 17 headers: { "Content-Type": "application/json" }, 18 }); 19 } 20 21 return new Response( 22 JSON.stringify({ error: "An unexpected error occurred" }), 23 { 24 status: 500, 25 headers: { "Content-Type": "application/json" }, 26 }, 27 ); 28}