Skip to content

Commit

Permalink
chore: don't log server errors for aborted requests (#5602)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 authored Mar 10, 2023
1 parent 66b33a8 commit e37115b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/no-log-on-aborted-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/server-runtime": patch
---

Don't log server errors for aborted requests as that is an expected flow
21 changes: 12 additions & 9 deletions packages/remix-server-runtime/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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 });
}

Expand Down Expand Up @@ -336,6 +331,7 @@ async function handleDocumentRequestRR(
entryContext
);
} catch (error: any) {
logServerErrorIfNotAborted(error, request, serverMode);
return returnLastResortErrorResponse(error, serverMode);
}
}
Expand Down Expand Up @@ -369,6 +365,7 @@ async function handleResourceRequestRR(
error.headers.set("X-Remix-Catch", "yes");
return error;
}
logServerErrorIfNotAborted(error, request, serverMode);
return returnLastResortErrorResponse(error, serverMode);
}
}
Expand All @@ -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) {
Expand Down

0 comments on commit e37115b

Please sign in to comment.