From 7249cf9defc5ca081c1e91a5dbc7bfa1b1871ee2 Mon Sep 17 00:00:00 2001 From: Onur Temizkan Date: Mon, 27 Nov 2023 21:42:36 +0000 Subject: [PATCH] fix(remix): Check the error data before spreading. (#9664) --- packages/remix/src/client/errors.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/remix/src/client/errors.tsx b/packages/remix/src/client/errors.tsx index a6afefbc0ef7..c2214bd283df 100644 --- a/packages/remix/src/client/errors.tsx +++ b/packages/remix/src/client/errors.tsx @@ -23,13 +23,14 @@ export function captureRemixErrorBoundaryError(error: unknown): string | undefin const eventData = isRemixErrorResponse ? { function: 'ErrorResponse', - ...error.data, + ...getErrorData(error), } : { function: 'ReactError', }; const actualError = isRemixErrorResponse ? getExceptionToCapture(error) : error; + eventId = captureException(actualError, { mechanism: { type: 'instrument', @@ -42,10 +43,21 @@ export function captureRemixErrorBoundaryError(error: unknown): string | undefin return eventId; } +function getErrorData(error: ErrorResponse): object { + if (isString(error.data)) { + return { + error: error.data, + }; + } + + return error.data; +} + function getExceptionToCapture(error: ErrorResponse): string | ErrorResponse { if (isString(error.data)) { return error.data; } + if (error.statusText) { return error.statusText; }