Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: don't log server errors for aborted requests #5602

Merged
merged 2 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Copy link
Contributor Author

@brophdawg11 brophdawg11 Feb 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the log to a utility that does the checking and lifted to the 2 places we call returnLastResortErrorResponse

}

function returnLastResortErrorResponse(error: any, serverMode?: ServerMode) {
let message = "Unexpected Server Error";

if (serverMode !== ServerMode.Production) {
Expand Down