File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -9034,6 +9034,32 @@ describe("a router", () => {
9034
9034
});
9035
9035
});
9036
9036
9037
+ it("action fetch with invalid body (json)", async () => {
9038
+ let t = setup({
9039
+ routes: [
9040
+ {
9041
+ id: "root",
9042
+ path: "/",
9043
+ hasErrorBoundary: true,
9044
+ },
9045
+ ],
9046
+ });
9047
+ let A = await t.fetch("/", {
9048
+ formMethod: "post",
9049
+ body: "not json",
9050
+ formEncType: "application/json",
9051
+ });
9052
+ expect(A.fetcher).toBe(IDLE_FETCHER);
9053
+ expect(t.router.state.errors).toEqual({
9054
+ index: new ErrorResponse(
9055
+ 400,
9056
+ "Bad Request",
9057
+ new Error("Unable to encode submission body"),
9058
+ true
9059
+ ),
9060
+ });
9061
+ });
9062
+
9037
9063
it("handles fetcher errors at contextual route boundaries", async () => {
9038
9064
let t = setup({
9039
9065
routes: [
Original file line number Diff line number Diff line change @@ -1665,12 +1665,18 @@ export function createRouter(init: RouterInit): Router {
1665
1665
return ;
1666
1666
}
1667
1667
1668
- let { path, submission } = normalizeNavigateOptions (
1668
+ let { path, submission, error } = normalizeNavigateOptions (
1669
1669
future . v7_normalizeFormMethod ,
1670
1670
true ,
1671
1671
normalizedPath ,
1672
1672
opts
1673
1673
) ;
1674
+
1675
+ if ( error ) {
1676
+ setFetcherError ( key , routeId , error ) ;
1677
+ return ;
1678
+ }
1679
+
1674
1680
let match = getTargetMatch ( matches , path ) ;
1675
1681
1676
1682
pendingPreventScrollReset = ( opts && opts . preventScrollReset ) === true ;
You can’t perform that action at this time.
0 commit comments