mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-10 13:15:47 -05:00
Fix sploosh build stat pages returning 404
This commit is contained in:
@@ -6,7 +6,7 @@ import { Ability } from "~/components/Ability";
|
||||
import { Main } from "~/components/Main";
|
||||
import { useTranslation } from "~/hooks/useTranslation";
|
||||
import { i18next } from "~/modules/i18n";
|
||||
import { notFoundIfFalsy, type SendouRouteHandle } from "~/utils/remix";
|
||||
import { notFoundIfNullLike, type SendouRouteHandle } from "~/utils/remix";
|
||||
import { makeTitle } from "~/utils/strings";
|
||||
import { weaponNameSlugToId } from "~/utils/unslugify.server";
|
||||
import {
|
||||
@@ -60,7 +60,7 @@ export const handle: SendouRouteHandle = {
|
||||
export const loader = async ({ params, request }: LoaderArgs) => {
|
||||
const t = await i18next.getFixedT(request, ["builds", "weapons", "common"]);
|
||||
const slug = params["slug"];
|
||||
const weaponId = notFoundIfFalsy(weaponNameSlugToId(slug));
|
||||
const weaponId = notFoundIfNullLike(weaponNameSlugToId(slug));
|
||||
|
||||
const weaponName = t(`weapons:MAIN_${weaponId}`);
|
||||
|
||||
|
||||
@@ -12,8 +12,7 @@ import { abilityPointCountsToAverages } from "../build-stats-utils";
|
||||
import { Ability } from "~/components/Ability";
|
||||
import styles from "../build-stats.css";
|
||||
import { WeaponImage } from "~/components/Image";
|
||||
import type { SendouRouteHandle } from "~/utils/remix";
|
||||
import { notFoundIfFalsy } from "~/utils/remix";
|
||||
import { notFoundIfNullLike, type SendouRouteHandle } from "~/utils/remix";
|
||||
import { MAX_AP, ONE_HOUR_IN_MS, TWELVE_HOURS_IN_MS } from "~/constants";
|
||||
import { useTranslation } from "~/hooks/useTranslation";
|
||||
import {
|
||||
@@ -70,7 +69,7 @@ export const handle: SendouRouteHandle = {
|
||||
|
||||
export const loader = async ({ params, request }: LoaderArgs) => {
|
||||
const t = await i18next.getFixedT(request, ["builds", "weapons", "common"]);
|
||||
const weaponId = notFoundIfFalsy(weaponNameSlugToId(params["slug"]));
|
||||
const weaponId = notFoundIfNullLike(weaponNameSlugToId(params["slug"]));
|
||||
|
||||
const weaponName = t(`weapons:MAIN_${weaponId}`);
|
||||
|
||||
|
||||
@@ -9,6 +9,13 @@ export function notFoundIfFalsy<T>(value: T | null | undefined): T {
|
||||
return value;
|
||||
}
|
||||
|
||||
export function notFoundIfNullLike<T>(value: T | null | undefined): T {
|
||||
if (value === null || value === undefined)
|
||||
throw new Response(null, { status: 404 });
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
export function badRequestIfFalsy<T>(value: T | null | undefined): T {
|
||||
if (!value) throw new Response(null, { status: 400 });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user