diff --git a/apps/api/src/core/services/hono-error-handler/hono-error-handler.service.ts b/apps/api/src/core/services/hono-error-handler/hono-error-handler.service.ts index a63e25a77..f05a8188e 100644 --- a/apps/api/src/core/services/hono-error-handler/hono-error-handler.service.ts +++ b/apps/api/src/core/services/hono-error-handler/hono-error-handler.service.ts @@ -39,8 +39,12 @@ export class HonoErrorHandlerService { } private async reportError(error: Error, c: Context): Promise { - const id = this.sentry.captureEvent(await this.getSentryEvent(error, c)); - this.logger.info({ event: "SENTRY_EVENT_REPORTED", id }); + try { + const id = this.sentry.captureEvent(await this.getSentryEvent(error, c)); + this.logger.info({ event: "SENTRY_EVENT_REPORTED", id }); + } catch (e) { + this.logger.error(e); + } } private async getSentryEvent(error: Error, c: Context): Promise { @@ -48,7 +52,7 @@ export class HonoErrorHandlerService { method: c.req.method, url: c.req.url, headers: omit(Object.fromEntries(c.req.raw.headers), ["x-anonymous-user-id"]), - body: await c.req.json() + body: await this.getSentryEventRequestBody(c) }); const currentSpan = trace.getSpan(context.active()); @@ -65,4 +69,18 @@ export class HonoErrorHandlerService { return event; } + + private async getSentryEventRequestBody(c: Context) { + switch (c.req.header("content-type")) { + case "text/plain": + return await c.req.text(); + case "application/json": + return await c.req.json(); + case "application/x-www-form-urlencoded": + case "multipart/form-data": + return await c.req.parseBody(); + default: + return undefined; + } + } }