Skip to content

Commit 779eb56

Browse files
fix(dashboard): properly handle GitHub auth errors with specific messages (#4785)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Kapil Gowru <[email protected]>
1 parent dd3f4d7 commit 779eb56

File tree

4 files changed

+43
-15
lines changed

4 files changed

+43
-15
lines changed

packages/fern-dashboard/src/app/services/dal/github/validators.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { RepoIdentifier } from "./types";
1010
export type GithubRepoValidationError =
1111
| { type: "REPO_NOT_CONNECTED" }
1212
| { type: "MALFORMED_GITHUB_URL"; url: string }
13+
| { type: "DOMAIN_NOT_REGISTERED" }
1314
| { type: "FERN_BOT_NOT_INSTALLED" }
1415
| { type: "FERN_CONFIG_JSON_ORG_MISMATCH" }
1516
| FernConfigJsonErrors

packages/fern-dashboard/src/components/docs-page/visual-editor-section/VisualEditorSection.tsx

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,42 @@ export async function VisualEditorSection({
3232

3333
const githubUrl = githubUrlResult.success ? githubUrlResult.githubUrl : undefined;
3434

35-
// Ensure we have a proper GithubAuthState, not an error result
36-
const githubAuthState: GithubAuthState =
37-
"validationResult" in githubAuthStateResult
38-
? githubAuthStateResult
39-
: {
40-
validationResult: {
41-
ok: false,
42-
error: {
43-
type: "UNEXPECTED_ERROR",
44-
message: "Failed to load GitHub auth state"
45-
}
46-
},
47-
sourceRepo: undefined,
48-
isLoading: false
49-
};
35+
// Ensure we have a proper GithubAuthState, handling both error shapes
36+
let githubAuthState: GithubAuthState;
37+
38+
if (!githubUrlResult.success) {
39+
githubAuthState = {
40+
validationResult: {
41+
ok: false,
42+
error: githubUrlResult.error
43+
},
44+
sourceRepo: undefined,
45+
isLoading: false
46+
};
47+
} else if ("success" in githubAuthStateResult && githubAuthStateResult.success === false) {
48+
githubAuthState = {
49+
validationResult: {
50+
ok: false,
51+
error: githubAuthStateResult.error
52+
},
53+
sourceRepo: undefined,
54+
isLoading: false
55+
};
56+
} else if ("validationResult" in githubAuthStateResult) {
57+
githubAuthState = githubAuthStateResult;
58+
} else {
59+
githubAuthState = {
60+
validationResult: {
61+
ok: false,
62+
error: {
63+
type: "UNEXPECTED_ERROR",
64+
message: "Failed to load GitHub auth state"
65+
}
66+
},
67+
sourceRepo: undefined,
68+
isLoading: false
69+
};
70+
}
5071

5172
if (!githubAuthState.validationResult.ok) {
5273
return (

packages/fern-dashboard/src/components/docs-page/visual-editor-section/VisualEditorValidationErrorHandler.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ export function VisualEditorValidationErrorHandler({ error, orgName, site, githu
4343
case "MALFORMED_GITHUB_URL":
4444
return <WarningNote>{getValidationErrorMessage(error)}</WarningNote>;
4545

46+
case "DOMAIN_NOT_REGISTERED":
47+
return <WarningNote>{getValidationErrorMessage(error)}</WarningNote>;
48+
4649
case "REPO_NOT_FOUND":
4750
return <WarningNote>{getValidationErrorMessage(error)}</WarningNote>;
4851

packages/fern-dashboard/src/utils/errors.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const ERROR_DIGEST_MESSAGES: Record<ERROR_DIGEST_KEYS, string> = {
2929
"You do not have write permission to the underlying GitHub repo. Please contact your GitHub admin for access.",
3030
MALFORMED_GITHUB_URL:
3131
"The provided GitHub URL is not valid. Please ensure you're using a valid GitHub repository URL.",
32+
DOMAIN_NOT_REGISTERED: "This docs domain is not registered. Please contact support to register your domain.",
3233
FERN_CONFIG_JSON_ORG_MISMATCH:
3334
"The organization in fern.config.json does not match your current organization. Please update the configuration file.",
3435
FERN_CONFIG_JSON_MISSING:
@@ -51,6 +52,8 @@ export function getValidationErrorMessage(error: GithubRepoValidationError): str
5152
return ERROR_DIGEST_MESSAGES.REPO_NOT_CONNECTED;
5253
case "MALFORMED_GITHUB_URL":
5354
return `${ERROR_DIGEST_MESSAGES.MALFORMED_GITHUB_URL} URL: ${error.url}`;
55+
case "DOMAIN_NOT_REGISTERED":
56+
return ERROR_DIGEST_MESSAGES.DOMAIN_NOT_REGISTERED;
5457
case "FERN_BOT_NOT_INSTALLED":
5558
return ERROR_DIGEST_MESSAGES.FERN_BOT_NOT_INSTALLED;
5659
case "FERN_CONFIG_JSON_ORG_MISMATCH":

0 commit comments

Comments
 (0)