Skip to content

Commit

Permalink
move into util
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Feb 28, 2023
1 parent 18e912a commit 71f1a8f
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 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,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);
}
}
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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";

Expand Down

0 comments on commit 71f1a8f

Please sign in to comment.