Skip to content

Commit 9b9c072

Browse files
0xFirekeeperclaude
andauthored
chore(dashboard): move chain SEO fetch to seo-pages.thirdweb.xyz
Point the chain SEO fetch at seo-pages.thirdweb.xyz; degrade to undefined on failure instead of caching it. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 50e6b66 commit 9b9c072

1 file changed

Lines changed: 37 additions & 17 deletions

File tree

  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/apis

‎apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/apis/chain-seo.ts‎

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,43 @@ type ChainSeo = {
2828
};
2929
};
3030

31-
export const fetchChainSeo = unstable_cache(
32-
async (chainId: number) => {
33-
const url = new URL(
34-
`https://seo-pages-generator-5814.zeet-nftlabs.zeet.app/chain/${chainId}`,
35-
);
36-
const res = await fetch(url, {
37-
headers: {
38-
"Content-Type": "application/json",
39-
},
40-
});
41-
42-
if (!res.ok) {
43-
return undefined;
44-
}
45-
46-
return res.json() as Promise<ChainSeo>;
47-
},
31+
async function fetchChainSeoUncached(
32+
chainId: number,
33+
): Promise<ChainSeo | undefined> {
34+
const url = new URL(`https://seo-pages.thirdweb.xyz/chain/${chainId}`);
35+
36+
const res = await fetch(url, {
37+
headers: { "Content-Type": "application/json" },
38+
});
39+
40+
// 4xx means this chain simply has no SEO entry -- a stable answer worth caching.
41+
if (res.status >= 400 && res.status < 500) {
42+
return undefined;
43+
}
44+
45+
// 5xx (or any other non-OK) is transient. Throw so unstable_cache does not
46+
// persist the failure and starve the page of SEO for a full day.
47+
if (!res.ok) {
48+
throw new Error(`chain SEO fetch failed: ${res.status}`);
49+
}
50+
51+
return (await res.json()) as ChainSeo;
52+
}
53+
54+
const fetchChainSeoCached = unstable_cache(
55+
fetchChainSeoUncached,
4856
["chain-seo"],
4957
{ revalidate: 60 * 60 * 24 }, // 24 hours
5058
);
59+
60+
export async function fetchChainSeo(
61+
chainId: number,
62+
): Promise<ChainSeo | undefined> {
63+
// SEO copy is decorative: a failure must never take the page down. A transient
64+
// error propagates out of the cache uncached, and we degrade to undefined here.
65+
try {
66+
return await fetchChainSeoCached(chainId);
67+
} catch {
68+
return undefined;
69+
}
70+
}

0 commit comments

Comments
 (0)