Skip to content

Instantly share code, notes, and snippets.

@kiliman
Created April 27, 2023 21:09
Show Gist options
  • Save kiliman/a7d7e90d30b0d01e5ffe5426c9dfab69 to your computer and use it in GitHub Desktop.
Save kiliman/a7d7e90d30b0d01e5ffe5426c9dfab69 to your computer and use it in GitHub Desktop.
Remix: Patch to fix incorrect status 500 errors (see https://github.com/remix-run/remix/issues/5507)
diff --git a/node_modules/@remix-run/server-runtime/dist/responses.js b/node_modules/@remix-run/server-runtime/dist/responses.js
index d042d61..1e6d5c6 100644
--- a/node_modules/@remix-run/server-runtime/dist/responses.js
+++ b/node_modules/@remix-run/server-runtime/dist/responses.js
@@ -47,7 +47,7 @@ function isDeferredData(value) {
return deferred && typeof deferred === "object" && typeof deferred.data === "object" && typeof deferred.subscribe === "function" && typeof deferred.cancel === "function" && typeof deferred.resolveData === "function";
}
function isResponse(value) {
- return value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined";
+ return value instanceof router.ErrorResponse || (value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined");
}
const redirectStatusCodes = new Set([301, 302, 303, 307, 308]);
function isRedirectStatusCode(statusCode) {
diff --git a/node_modules/@remix-run/server-runtime/dist/server.js b/node_modules/@remix-run/server-runtime/dist/server.js
index fd10bc5..b924771 100644
--- a/node_modules/@remix-run/server-runtime/dist/server.js
+++ b/node_modules/@remix-run/server-runtime/dist/server.js
@@ -110,6 +110,9 @@ async function handleDataRequestRR(serverMode, staticHandler, routeId, request,
return response;
} catch (error) {
if (responses.isResponse(error)) {
+ if (error.headers === undefined) {
+ error.headers = new Headers()
+ }
error.headers.set("X-Remix-Catch", "yes");
return error;
}
@@ -251,6 +254,9 @@ async function handleResourceRequestRR(serverMode, staticHandler, routeId, reque
return response;
} catch (error) {
if (responses.isResponse(error)) {
+ if (error.headers === undefined) {
+ error.headers = new Headers()
+ }
// Note: Not functionally required but ensures that our response headers
// match identically to what Remix returns
error.headers.set("X-Remix-Catch", "yes");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment