Skip to content

Commit b98e82d

Browse files
authored
Specify ErrorResponse as interface to provide obvious contract (#10876)
1 parent da57748 commit b98e82d

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

.changeset/error-response-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/router": patch
3+
---
4+
5+
Fix `ErrorResponse` type to avoid leaking internal field

contributors.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,4 @@
238238
- yionr
239239
- yuleicul
240240
- zheng-chuang
241+
- sgrishchenko

packages/router/utils.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,11 +1533,21 @@ export const redirectDocument: RedirectFunction = (url, init) => {
15331533
return response;
15341534
};
15351535

1536+
export type ErrorResponse = {
1537+
status: number;
1538+
statusText: string;
1539+
data: any;
1540+
};
1541+
15361542
/**
15371543
* @private
15381544
* Utility class we use to hold auto-unwrapped 4xx/5xx Response bodies
1545+
*
1546+
* We don't export the class for public use since it's an implementation
1547+
* detail, but we export the interface above so folks can build their own
1548+
* abstractions around instances via isRouteErrorResponse()
15391549
*/
1540-
export class ErrorResponseImpl {
1550+
export class ErrorResponseImpl implements ErrorResponse {
15411551
status: number;
15421552
statusText: string;
15431553
data: any;
@@ -1562,11 +1572,6 @@ export class ErrorResponseImpl {
15621572
}
15631573
}
15641574

1565-
// We don't want the class exported since usage of it at runtime is an
1566-
// implementation detail, but we do want to export the shape so folks can
1567-
// build their own abstractions around instances via isRouteErrorResponse()
1568-
export type ErrorResponse = InstanceType<typeof ErrorResponseImpl>;
1569-
15701575
/**
15711576
* Check if the given error is an ErrorResponse generated from a 4xx/5xx
15721577
* Response thrown from an action/loader

0 commit comments

Comments
 (0)