From 18e912ae925807ee48eee61fbb3003e8e2f5cb2f Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Tue, 28 Feb 2023 11:48:25 -0500 Subject: [PATCH 1/2] chore: don't log server errors for aborted requests --- .changeset/no-log-on-aborted-request.md | 5 +++++ packages/remix-server-runtime/server.ts | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 .changeset/no-log-on-aborted-request.md diff --git a/.changeset/no-log-on-aborted-request.md b/.changeset/no-log-on-aborted-request.md new file mode 100644 index 00000000000..ce4780de5bd --- /dev/null +++ b/.changeset/no-log-on-aborted-request.md @@ -0,0 +1,5 @@ +--- +"@remix-run/server-runtime": patch +--- + +Don't log server errors for aborted requests as that is an expected flow diff --git a/packages/remix-server-runtime/server.ts b/packages/remix-server-runtime/server.ts index 0c6503a3588..929c75ded2e 100644 --- a/packages/remix-server-runtime/server.ts +++ b/packages/remix-server-runtime/server.ts @@ -336,6 +336,9 @@ async function handleDocumentRequestRR( entryContext ); } catch (error: any) { + if (serverMode !== ServerMode.Test && !request.signal.aborted) { + console.error(error); + } return returnLastResortErrorResponse(error, serverMode); } } @@ -369,6 +372,9 @@ async function handleResourceRequestRR( error.headers.set("X-Remix-Catch", "yes"); return error; } + if (serverMode !== ServerMode.Test && !request.signal.aborted) { + console.error(error); + } return returnLastResortErrorResponse(error, serverMode); } } @@ -383,10 +389,6 @@ async function errorBoundaryError(error: Error, status: number) { } function returnLastResortErrorResponse(error: any, serverMode?: ServerMode) { - if (serverMode !== ServerMode.Test) { - console.error(error); - } - let message = "Unexpected Server Error"; if (serverMode !== ServerMode.Production) { From 71f1a8f977548806b852596549ebc422e2cf0961 Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Tue, 28 Feb 2023 11:54:00 -0500 Subject: [PATCH 2/2] move into util --- packages/remix-server-runtime/server.ts | 27 +++++++++++++------------ 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/remix-server-runtime/server.ts b/packages/remix-server-runtime/server.ts index 929c75ded2e..67817d3cd7b 100644 --- a/packages/remix-server-runtime/server.ts +++ b/packages/remix-server-runtime/server.ts @@ -182,9 +182,7 @@ async function handleDataRequestRR( errorInstance = error.error || errorInstance; } - if (serverMode !== ServerMode.Test && !request.signal.aborted) { - console.error(errorInstance); - } + logServerErrorIfNotAborted(errorInstance, request, serverMode); if ( serverMode === ServerMode.Development && @@ -259,10 +257,7 @@ async function handleDocumentRequestRR( requestContext: loadContext, }); } catch (error: unknown) { - if (!request.signal.aborted && serverMode !== ServerMode.Test) { - console.error(error); - } - + logServerErrorIfNotAborted(error, request, serverMode); return new Response(null, { status: 500 }); } @@ -336,9 +331,7 @@ async function handleDocumentRequestRR( entryContext ); } catch (error: any) { - if (serverMode !== ServerMode.Test && !request.signal.aborted) { - console.error(error); - } + logServerErrorIfNotAborted(error, request, serverMode); return returnLastResortErrorResponse(error, serverMode); } } @@ -372,9 +365,7 @@ async function handleResourceRequestRR( error.headers.set("X-Remix-Catch", "yes"); return error; } - if (serverMode !== ServerMode.Test && !request.signal.aborted) { - console.error(error); - } + logServerErrorIfNotAborted(error, request, serverMode); return returnLastResortErrorResponse(error, serverMode); } } @@ -388,6 +379,16 @@ async function errorBoundaryError(error: Error, status: number) { }); } +function logServerErrorIfNotAborted( + error: unknown, + request: Request, + serverMode: ServerMode +) { + if (serverMode !== ServerMode.Test && !request.signal.aborted) { + console.error(error); + } +} + function returnLastResortErrorResponse(error: any, serverMode?: ServerMode) { let message = "Unexpected Server Error";