Skip to content

Commit

Permalink
app routes: catch loader errors in meta function
Browse files Browse the repository at this point in the history
  • Loading branch information
cmnord committed Mar 31, 2023
1 parent 8051aa3 commit c1aacf6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
12 changes: 9 additions & 3 deletions app/routes/$gameId.solo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ import { getGame } from "~/models/game.server";
import { getOrCreateUserSession } from "~/session.server";
import { getRandomName } from "~/utils/name";

export const meta: MetaFunction<typeof loader> = ({ data }) => ({
title: data.game.title,
});
export const meta: MetaFunction<typeof loader> = ({ data }) => {
try {
return {
title: data.game.title,
};
} catch (error: unknown) {
return {};
}
};

export async function loader({ request, params }: LoaderArgs) {
const gameId = params.gameId;
Expand Down
12 changes: 9 additions & 3 deletions app/routes/mock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import GameComponent from "~/components/game";
import { GameEngineContext, useSoloGameEngine } from "~/engine";
import { getMockGame } from "~/models/mock.server";

export const meta: MetaFunction<typeof loader> = ({ data }) => ({
title: data.game.title,
});
export const meta: MetaFunction<typeof loader> = ({ data }) => {
try {
return {
title: data.game.title,
};
} catch (error: unknown) {
return {};
}
};

export async function loader() {
const game = await getMockGame();
Expand Down
12 changes: 9 additions & 3 deletions app/routes/room.$roomName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ import { getRoom } from "~/models/room.server";
import { getOrCreateUserSession } from "~/session.server";
import { getRandomName } from "~/utils/name";

export const meta: MetaFunction<typeof loader> = ({ data }) => ({
title: data.game.title,
});
export const meta: MetaFunction<typeof loader> = ({ data }) => {
try {
return {
title: data.game.title,
};
} catch (error: unknown) {
return {};
}
};

export async function loader({ request, params }: LoaderArgs) {
const roomName = params.roomName;
Expand Down

0 comments on commit c1aacf6

Please sign in to comment.