Skip to content

Commit 6012757

Browse files
authored
chore: dont cache errors (#3298)
1 parent 985f06c commit 6012757

File tree

1 file changed

+15
-7
lines changed
  • packages/fern-dashboard/src/app/api/get-docs-github-source

1 file changed

+15
-7
lines changed

packages/fern-dashboard/src/app/api/get-docs-github-source/handler.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default async function getDocsGithubSourceHandler({
2323
token: string;
2424
userId: Auth0UserID;
2525
}): Promise<GithubSourceRepo> {
26-
// Cache the result for 5 minutes to avoid repeated API calls
26+
// Only cache successful responses; do not cache failures
2727
return unstable_cache(
2828
async () => {
2929
const docsUrlMetadata = await getDocsUrlMetadata({
@@ -34,7 +34,8 @@ export default async function getDocsGithubSourceHandler({
3434
// the docs url is user-supplied (parsed from the page url) so it's ok if it
3535
// doesn't exist
3636
if (docsUrlMetadata.error.error === "DomainNotRegisteredError") {
37-
return EMPTY_RESPONSE;
37+
// Don't cache this failure, so throw to skip cache
38+
throw new Error("DomainNotRegisteredError");
3839
}
3940

4041
console.error(
@@ -49,17 +50,20 @@ export default async function getDocsGithubSourceHandler({
4950
}
5051

5152
if (docsUrlMetadata.body.gitUrl == null) {
52-
return EMPTY_RESPONSE;
53+
// Don't cache this failure, so throw to skip cache
54+
throw new Error("NoGitUrl");
5355
}
5456

5557
const octokit = await getOctokit(userId);
5658
if (octokit == null) {
57-
return EMPTY_RESPONSE;
59+
// Don't cache this failure, so throw to skip cache
60+
throw new Error("NoOctokit");
5861
}
5962

6063
const [owner, repo] = docsUrlMetadata.body.gitUrl.split("/").slice(-2);
6164
if (owner == null || repo == null) {
62-
return EMPTY_RESPONSE;
65+
// Don't cache this failure, so throw to skip cache
66+
throw new Error("InvalidGitUrl");
6367
}
6468

6569
try {
@@ -76,13 +80,17 @@ export default async function getDocsGithubSourceHandler({
7680
};
7781
} catch (error) {
7882
console.error("Failed to get repo info", error);
79-
return EMPTY_RESPONSE;
83+
// Don't cache this failure, so throw to skip cache
84+
throw new Error("FailedToGetRepoInfo");
8085
}
8186
},
8287
[`github-source-${url}-${userId}`],
8388
{
8489
revalidate: 300, // 5 minutes
8590
tags: [`github-source-${url}`],
8691
}
87-
)();
92+
)().catch(() => {
93+
// On any error, return EMPTY_RESPONSE (but don't cache the error)
94+
return EMPTY_RESPONSE;
95+
});
8896
}

0 commit comments

Comments
 (0)