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

feat: export ErrorResponse type #7244

Merged
merged 3 commits into from
Aug 25, 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
9 changes: 9 additions & 0 deletions .changeset/error-response-type.md
Original file line number Diff line number Diff line change
@@ -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`
1 change: 1 addition & 0 deletions packages/remix-cloudflare/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type {
CookieSignatureOptions,
DataFunctionArgs,
EntryContext,
ErrorResponse,
HandleDataRequestFunction,
HandleDocumentRequestFunction,
HeadersArgs,
Expand Down
1 change: 1 addition & 0 deletions packages/remix-deno/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type {
CookieSignatureOptions,
DataFunctionArgs,
EntryContext,
ErrorResponse,
HandleDataRequestFunction,
HandleDocumentRequestFunction,
HandleErrorFunction,
Expand Down
1 change: 1 addition & 0 deletions packages/remix-node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type {
CookieSignatureOptions,
DataFunctionArgs,
EntryContext,
ErrorResponse,
HandleDataRequestFunction,
HandleDocumentRequestFunction,
HeadersArgs,
Expand Down
4 changes: 2 additions & 2 deletions packages/remix-react/errors.ts
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/remix-react/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export type { RemixBrowserProps } from "./browser";
export { RemixBrowser } from "./browser";
export type {
ErrorResponse,
Fetcher,
FetcherWithComponents,
FormEncType,
Expand Down
4 changes: 2 additions & 2 deletions packages/remix-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions packages/remix-server-runtime/__tests__/handle-error-test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -126,7 +126,7 @@ describe("handleError", () => {
});
await handler(request);
expect(handleErrorSpy).toHaveBeenCalledWith(
new ErrorResponse(
new ErrorResponseImpl(
405,
"Method Not Allowed",
new Error(
Expand Down Expand Up @@ -182,7 +182,7 @@ describe("handleError", () => {
});
await handler(request);
expect(handleErrorSpy).toHaveBeenCalledWith(
new ErrorResponse(
new ErrorResponseImpl(
405,
"Method Not Allowed",
new Error(
Expand Down
1 change: 1 addition & 0 deletions packages/remix-server-runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type {
CookieSignatureOptions,
DataFunctionArgs,
EntryContext,
ErrorResponse,
FlashSessionData,
HandleDataRequestFunction,
HandleDocumentRequestFunction,
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-server-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions packages/remix-server-runtime/reexport.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type { ErrorResponse } from "@remix-run/router";

export type {
HandleDataRequestFunction,
HandleDocumentRequestFunction,
Expand Down
7 changes: 6 additions & 1 deletion packages/remix-server-runtime/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
});

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
),
Expand Down
4 changes: 2 additions & 2 deletions packages/remix-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2125,10 +2125,10 @@
"@changesets/types" "^5.0.0"
dotenv "^8.1.0"

"@remix-run/[email protected]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/[email protected]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"
Expand Down Expand Up @@ -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==

[email protected]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==
[email protected]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"

[email protected]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==
[email protected]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"
Expand Down