diff --git a/src/app/(dashboard)/[guildUrlName]/[pageUrlName]/page.tsx b/src/app/(dashboard)/[guildUrlName]/[pageUrlName]/page.tsx index f35cb1fba4..9b6a1aa843 100644 --- a/src/app/(dashboard)/[guildUrlName]/[pageUrlName]/page.tsx +++ b/src/app/(dashboard)/[guildUrlName]/[pageUrlName]/page.tsx @@ -6,7 +6,7 @@ import { Button } from "@/components/ui/Button"; import { Card } from "@/components/ui/Card"; import { ScrollArea } from "@/components/ui/ScrollArea"; import { Skeleton } from "@/components/ui/Skeleton"; -import { CustomError } from "@/lib/error"; +import { CustomError, FetchError } from "@/lib/error"; import { rewardBatchOptions, roleBatchOptions } from "@/lib/options"; import type { Schemas } from "@guildxyz/types"; import { Lock } from "@phosphor-icons/react/dist/ssr"; @@ -14,7 +14,6 @@ import { useSuspenseQuery } from "@tanstack/react-query"; import { useParams } from "next/navigation"; import { Suspense } from "react"; import { ErrorBoundary } from "react-error-boundary"; -import { ZodError } from "zod"; const GuildPage = () => { const { pageUrlName, guildUrlName } = useParams<{ @@ -48,12 +47,11 @@ const GuildPage = () => { const RoleCard = ({ role }: { role: Schemas["Role"] }) => { const blacklistedRoleName = "Member"; if (role.name === blacklistedRoleName) { - throw new ZodError([]); - //throw new FetchError({ - // recoverable: true, - // message: `Failed to show ${role.name} role`, - // cause: FetchError.expected`${{ roleName: role.name }} to not match ${{ blacklistedRoleName }}`, - //}); + throw new FetchError({ + recoverable: true, + message: `Failed to show ${role.name} role`, + cause: FetchError.expected`${{ roleName: role.name }} to not match ${{ blacklistedRoleName }}`, + }); } const { data: rewards } = useSuspenseQuery( rewardBatchOptions({ roleId: role.id }), diff --git a/src/app/(dashboard)/[guildUrlName]/layout.tsx b/src/app/(dashboard)/[guildUrlName]/layout.tsx index a02183106e..b01405616a 100644 --- a/src/app/(dashboard)/[guildUrlName]/layout.tsx +++ b/src/app/(dashboard)/[guildUrlName]/layout.tsx @@ -9,7 +9,9 @@ import { userOptions, } from "@/lib/options"; import type { DynamicRoute } from "@/lib/types"; +import { Status } from "@reflet/http"; import { HydrationBoundary, dehydrate } from "@tanstack/react-query"; +import { notFound } from "next/navigation"; import { type PropsWithChildren, Suspense } from "react"; import { GuildTabs, GuildTabsSkeleton } from "./components/GuildTabs"; import { JoinButton } from "./components/JoinButton"; @@ -65,8 +67,11 @@ const GuildLayout = async ({ }).queryKey, ); - if (guild?.error || !guild?.data) { - throw new Error(`Failed to fetch guild ${guild?.error?.status || ""}`); + if (guild?.error?.partialResponse.status === Status.NotFound) { + notFound(); + } + if (!guild?.data) { + throw new Error("Failed to fetch guild"); } return ( diff --git a/src/app/(dashboard)/explorer/components/InfiniteScrollGuilds.tsx b/src/app/(dashboard)/explorer/components/InfiniteScrollGuilds.tsx index 4078a7b89d..f64d1e7844 100644 --- a/src/app/(dashboard)/explorer/components/InfiniteScrollGuilds.tsx +++ b/src/app/(dashboard)/explorer/components/InfiniteScrollGuilds.tsx @@ -51,7 +51,7 @@ export const InfiniteScrollGuilds = () => { ? // biome-ignore lint: it's safe to use index as key in this case [...Array(PAGE_SIZE)].map((_, i) => ) : guilds.map((guild, _i) => ( - + ))}
{ - console.log(error.cause); + if (error.cause) console.log(error.cause); + return ( { return ( ); -} +}; + +export default NotFound; diff --git a/src/lib/fetchGuildApi.ts b/src/lib/fetchGuildApi.ts index 8332b0de7c..089bd74357 100644 --- a/src/lib/fetchGuildApi.ts +++ b/src/lib/fetchGuildApi.ts @@ -140,8 +140,11 @@ const unpackFetcher = (fetcher: typeof fetchGuildApi) => { return async ( ...args: Parameters ) => { - const { data, status } = await fetcher(...args); - return status === "error" ? Promise.reject(data) : data; + const { data, status, response } = await fetcher(...args); + const partialResponse = { status: response.status }; + return status === "error" + ? Promise.reject({ data, partialResponse }) + : data; }; }; diff --git a/src/lib/types.ts b/src/lib/types.ts index 2faafb886c..601bd35b7c 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -23,9 +23,14 @@ export type DynamicRoute> = { */ // TODO: align this to backend when error handling gets consistent export type ErrorLike = { - message: string; - status?: string; - error?: string; + data: { + message: string; + status?: string; + error?: string; + }; + partialResponse: { + status: number; + }; }; /**