diff --git a/.changeset/error-response-type.md b/.changeset/error-response-type.md new file mode 100644 index 00000000000..e605d9c9859 --- /dev/null +++ b/.changeset/error-response-type.md @@ -0,0 +1,9 @@ +--- +"@remix-run/cloudflare": patch +"@remix-run/deno": patch +"@remix-run/node": patch +"@remix-run/react": patch +"@remix-run/server-runtime": patch +--- + +Export proper `ErrorResponse` type for usage alongside `isRouteErrorResponse` diff --git a/packages/remix-cloudflare/index.ts b/packages/remix-cloudflare/index.ts index 3b7e0b9992c..33f0769bd35 100644 --- a/packages/remix-cloudflare/index.ts +++ b/packages/remix-cloudflare/index.ts @@ -38,6 +38,7 @@ export type { CookieSignatureOptions, DataFunctionArgs, EntryContext, + ErrorResponse, HandleDataRequestFunction, HandleDocumentRequestFunction, HeadersArgs, diff --git a/packages/remix-deno/index.ts b/packages/remix-deno/index.ts index bd4b73be0d6..cf121bfb5e0 100644 --- a/packages/remix-deno/index.ts +++ b/packages/remix-deno/index.ts @@ -41,6 +41,7 @@ export type { CookieSignatureOptions, DataFunctionArgs, EntryContext, + ErrorResponse, HandleDataRequestFunction, HandleDocumentRequestFunction, HandleErrorFunction, diff --git a/packages/remix-node/index.ts b/packages/remix-node/index.ts index 7003c1aa54e..c74d8ed25cf 100644 --- a/packages/remix-node/index.ts +++ b/packages/remix-node/index.ts @@ -58,6 +58,7 @@ export type { CookieSignatureOptions, DataFunctionArgs, EntryContext, + ErrorResponse, HandleDataRequestFunction, HandleDocumentRequestFunction, HeadersArgs, diff --git a/packages/remix-react/errors.ts b/packages/remix-react/errors.ts index c2d95c6496a..dd98cbc16e1 100644 --- a/packages/remix-react/errors.ts +++ b/packages/remix-react/errors.ts @@ -1,5 +1,5 @@ import type { Router as RemixRouter } from "@remix-run/router"; -import { ErrorResponse } from "@remix-run/router"; +import { UNSAFE_ErrorResponseImpl as ErrorResponseImpl } from "@remix-run/router"; export function deserializeErrors( errors: RemixRouter["state"]["errors"] @@ -11,7 +11,7 @@ export function deserializeErrors( // Hey you! If you change this, please change the corresponding logic in // serializeErrors in remix-server-runtime/errors.ts :) if (val && val.__type === "RouteErrorResponse") { - serialized[key] = new ErrorResponse( + serialized[key] = new ErrorResponseImpl( val.status, val.statusText, val.data, diff --git a/packages/remix-react/index.tsx b/packages/remix-react/index.tsx index c995f615e40..e07c7818693 100644 --- a/packages/remix-react/index.tsx +++ b/packages/remix-react/index.tsx @@ -1,6 +1,7 @@ export type { RemixBrowserProps } from "./browser"; export { RemixBrowser } from "./browser"; export type { + ErrorResponse, Fetcher, FetcherWithComponents, FormEncType, diff --git a/packages/remix-react/package.json b/packages/remix-react/package.json index 445e094e045..0eb8c7a4876 100644 --- a/packages/remix-react/package.json +++ b/packages/remix-react/package.json @@ -16,9 +16,9 @@ "typings": "dist/index.d.ts", "module": "dist/esm/index.js", "dependencies": { - "@remix-run/router": "0.0.0-experimental-4286521e", + "@remix-run/router": "0.0.0-experimental-7b1bbb00", "@remix-run/server-runtime": "1.19.3", - "react-router-dom": "0.0.0-experimental-4286521e" + "react-router-dom": "0.0.0-experimental-7b1bbb00" }, "devDependencies": { "@testing-library/jest-dom": "^5.17.0", diff --git a/packages/remix-server-runtime/__tests__/handle-error-test.ts b/packages/remix-server-runtime/__tests__/handle-error-test.ts index dcc88f0fd64..439823b5bdb 100644 --- a/packages/remix-server-runtime/__tests__/handle-error-test.ts +++ b/packages/remix-server-runtime/__tests__/handle-error-test.ts @@ -1,4 +1,4 @@ -import { ErrorResponse } from "@remix-run/router"; +import { UNSAFE_ErrorResponseImpl as ErrorResponseImpl } from "@remix-run/router"; import type { ServerBuild } from "../build"; import { createRequestHandler } from "../server"; @@ -56,7 +56,7 @@ describe("handleError", () => { let request = new Request("http://example.com/", { method: "post" }); await handler(request); expect(handleErrorSpy).toHaveBeenCalledWith( - new ErrorResponse( + new ErrorResponseImpl( 405, "Method Not Allowed", new Error( @@ -126,7 +126,7 @@ describe("handleError", () => { }); await handler(request); expect(handleErrorSpy).toHaveBeenCalledWith( - new ErrorResponse( + new ErrorResponseImpl( 405, "Method Not Allowed", new Error( @@ -182,7 +182,7 @@ describe("handleError", () => { }); await handler(request); expect(handleErrorSpy).toHaveBeenCalledWith( - new ErrorResponse( + new ErrorResponseImpl( 405, "Method Not Allowed", new Error( diff --git a/packages/remix-server-runtime/index.ts b/packages/remix-server-runtime/index.ts index 038b6518e94..78cdc15aa5d 100644 --- a/packages/remix-server-runtime/index.ts +++ b/packages/remix-server-runtime/index.ts @@ -44,6 +44,7 @@ export type { CookieSignatureOptions, DataFunctionArgs, EntryContext, + ErrorResponse, FlashSessionData, HandleDataRequestFunction, HandleDocumentRequestFunction, diff --git a/packages/remix-server-runtime/package.json b/packages/remix-server-runtime/package.json index 90703972579..861045b0e95 100644 --- a/packages/remix-server-runtime/package.json +++ b/packages/remix-server-runtime/package.json @@ -16,7 +16,7 @@ "typings": "dist/index.d.ts", "module": "dist/esm/index.js", "dependencies": { - "@remix-run/router": "0.0.0-experimental-4286521e", + "@remix-run/router": "0.0.0-experimental-7b1bbb00", "@types/cookie": "^0.4.1", "@web3-storage/multipart-parser": "^1.0.0", "cookie": "^0.4.1", diff --git a/packages/remix-server-runtime/reexport.ts b/packages/remix-server-runtime/reexport.ts index db3d948e8b1..3b366baac9c 100644 --- a/packages/remix-server-runtime/reexport.ts +++ b/packages/remix-server-runtime/reexport.ts @@ -1,3 +1,5 @@ +export type { ErrorResponse } from "@remix-run/router"; + export type { HandleDataRequestFunction, HandleDocumentRequestFunction, diff --git a/packages/remix-server-runtime/server.ts b/packages/remix-server-runtime/server.ts index 227f5bd0627..de63313644f 100644 --- a/packages/remix-server-runtime/server.ts +++ b/packages/remix-server-runtime/server.ts @@ -51,7 +51,10 @@ export const createRequestHandler: CreateRequestHandlerFunction = ( build.entry.module.handleError || ((error, { request }) => { if (serverMode !== ServerMode.Test && !request.signal.aborted) { - console.error(isRouteErrorResponse(error) ? error.error : error); + console.error( + // @ts-expect-error This is "private" from users but intended for internal use + isRouteErrorResponse(error) && error.error ? error.error : error + ); } }); @@ -225,6 +228,7 @@ async function handleDocumentRequestRR( // Sanitize errors outside of development environments if (context.errors) { Object.values(context.errors).forEach((err) => { + // @ts-expect-error This is "private" from users but intended for internal use if (!isRouteErrorResponse(err) || err.error) { handleError(err); } @@ -353,6 +357,7 @@ function errorResponseToJson( ): Response { return routerJson( serializeError( + // @ts-expect-error This is "private" from users but intended for internal use errorResponse.error || new Error("Unexpected Server Error"), serverMode ), diff --git a/packages/remix-testing/package.json b/packages/remix-testing/package.json index 557a0561be1..14756c44afa 100644 --- a/packages/remix-testing/package.json +++ b/packages/remix-testing/package.json @@ -18,8 +18,8 @@ "dependencies": { "@remix-run/node": "1.19.3", "@remix-run/react": "1.19.3", - "@remix-run/router": "0.0.0-experimental-4286521e", - "react-router-dom": "0.0.0-experimental-4286521e" + "@remix-run/router": "0.0.0-experimental-7b1bbb00", + "react-router-dom": "0.0.0-experimental-7b1bbb00" }, "devDependencies": { "@types/node": "^18.17.1", diff --git a/yarn.lock b/yarn.lock index 30e78f2d70c..c16e5a775a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2125,10 +2125,10 @@ "@changesets/types" "^5.0.0" dotenv "^8.1.0" -"@remix-run/router@0.0.0-experimental-4286521e": - version "0.0.0-experimental-4286521e" - resolved "https://registry.npmjs.org/@remix-run/router/-/router-0.0.0-experimental-4286521e.tgz#3db770e0b9dc726251add1728c2e647095e476e0" - integrity sha512-tVqZUnmYwcfTMgo9sF4Ny8MdAWzLMeq5NY3Xsw36jmy9i3PQwM+hXlqE8Ilg43WeJQyP3Co5gdegKHdd7aC/zQ== +"@remix-run/router@0.0.0-experimental-7b1bbb00": + version "0.0.0-experimental-7b1bbb00" + resolved "https://registry.npmjs.org/@remix-run/router/-/router-0.0.0-experimental-7b1bbb00.tgz#53e8f0f94d4ae59cc5c96472582b9eed4277fc0c" + integrity sha512-ftRs73TmSs1muFgzrFqglifvRQKL4IXPp+FWpB+Vro9nPrYJrvT9U0zxqPpNOa11LT6zYH2+2YVsWsjfHnbErw== "@remix-run/web-blob@^3.0.5": version "3.0.5" @@ -10121,20 +10121,20 @@ react-refresh@^0.14.0: resolved "https://registry.npmjs.org/react-refresh/-/react-refresh-0.14.0.tgz" integrity sha512-wViHqhAd8OHeLS/IRMJjTSDHF3U9eWi62F/MledQGPdJGDhodXJ9PBLNGr6WWL7qlH12Mt3TyTpbS+hGXMjCzQ== -react-router-dom@0.0.0-experimental-4286521e: - version "0.0.0-experimental-4286521e" - resolved "https://registry.npmjs.org/react-router-dom/-/react-router-dom-0.0.0-experimental-4286521e.tgz#cb55ade67811d252e76b6a9dc675d17005dac70b" - integrity sha512-+ByHVuOeVABXbZe/enX32/QvJ8g47ILx6r7Iu8xqUxrE7vN1Gk4DTuB/s4frLRT8RtDC5xw+xoMTG9Ojzc+H9A== +react-router-dom@0.0.0-experimental-7b1bbb00: + version "0.0.0-experimental-7b1bbb00" + resolved "https://registry.npmjs.org/react-router-dom/-/react-router-dom-0.0.0-experimental-7b1bbb00.tgz#ac53ec77036ec4de08719677370b0dbd6a94a976" + integrity sha512-fGWVuY0LVaSM+FloQ9urDy1e1a9fX5Pq/lNP1dSnA2az2+M9qAkOeadSOdR0IMJmJU3l8rsh688Arhg/j3QAPQ== dependencies: - "@remix-run/router" "0.0.0-experimental-4286521e" - react-router "0.0.0-experimental-4286521e" + "@remix-run/router" "0.0.0-experimental-7b1bbb00" + react-router "0.0.0-experimental-7b1bbb00" -react-router@0.0.0-experimental-4286521e: - version "0.0.0-experimental-4286521e" - resolved "https://registry.npmjs.org/react-router/-/react-router-0.0.0-experimental-4286521e.tgz#0a78a34b1322d016956af796762e84bc2948e64c" - integrity sha512-hLyGDdQOVLEMnJ0xflGtLmCPX10cI7dLBJKnPq5BGG8dixE5L+Av9imM8j9rU7Qm67NDHrp1xcPkVLS9oCFuvg== +react-router@0.0.0-experimental-7b1bbb00: + version "0.0.0-experimental-7b1bbb00" + resolved "https://registry.npmjs.org/react-router/-/react-router-0.0.0-experimental-7b1bbb00.tgz#eae87bbfba7d28265ea55287b97c95eb147f7e91" + integrity sha512-7fdfoYJKv73CqivkA8VwXpkF+juw6GflK3HSXVQ+5wC/49for/+2mxk3Y/294C17xRSqiLeTb4mHC/olwNeZeQ== dependencies: - "@remix-run/router" "0.0.0-experimental-4286521e" + "@remix-run/router" "0.0.0-experimental-7b1bbb00" react@^18.2.0: version "18.2.0"