Skip to content

Commit

Permalink
fix(routing): include match error in return value
Browse files Browse the repository at this point in the history
This way the actual underlying error gets logged instead of vanishing into a black hole
  • Loading branch information
UberMouse committed Feb 12, 2024
1 parent e935bcb commit c1fd0f2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/routing/matchRoute/matchRoute.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ describe("matchRoute", () => {
});

it("returns a match-error type if there is a problem parsing the query/params schema", () => {
expect(matchRoute(routes, "", "/route2", "?foo=123")).toEqual({
expect(matchRoute(routes, "", "/route2", "?foo=123")).toMatchObject({
type: "match-error",
error: expect.any(Error),
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/routing/matchRoute/matchRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Return<TRoutes extends Route<any, any, any, any>[]> =
event: RoutingEvent<TRoutes[number]>;
}
| { type: "no-matches" }
| { type: "match-error" };
| { type: "match-error"; error: unknown };

/**
* @public
Expand Down Expand Up @@ -48,7 +48,7 @@ export function matchRoute<TRoutes extends Route<any, any, any, any>[]>(
if (matchingRoute === undefined) {
return { type: "no-matches" };
} else if (matchingRoute instanceof Error) {
return { type: "match-error" };
return { type: "match-error", error: matchingRoute };
}

return { type: "matched", route: matchingRoute, event: event as any };
Expand Down

0 comments on commit c1fd0f2

Please sign in to comment.