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..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,6 +331,7 @@ async function handleDocumentRequestRR( entryContext ); } catch (error: any) { + logServerErrorIfNotAborted(error, request, serverMode); return returnLastResortErrorResponse(error, serverMode); } } @@ -369,6 +365,7 @@ async function handleResourceRequestRR( error.headers.set("X-Remix-Catch", "yes"); return error; } + logServerErrorIfNotAborted(error, request, serverMode); return returnLastResortErrorResponse(error, serverMode); } } @@ -382,11 +379,17 @@ async function errorBoundaryError(error: Error, status: number) { }); } -function returnLastResortErrorResponse(error: any, serverMode?: ServerMode) { - if (serverMode !== ServerMode.Test) { +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"; if (serverMode !== ServerMode.Production) {