Skip to content

Commit

Permalink
fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed McConnell committed Nov 25, 2024
1 parent 60bbee4 commit 14c289f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/github/GitHubAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,16 @@ export function GitHubAuth({ onAuthComplete, onError, children }: GitHubAuthProp
});

if (!response.ok) {
const errorData = await response.json().catch(() => ({} as GitHubErrorResponse));
throw new Error(
errorData?.error ||
`Failed to start authentication process (${response.status})`
);
let errorMessage = `Failed to start authentication process (${response.status})`;
try {
const errorData: GitHubErrorResponse = await response.json();
if (errorData.error) {
errorMessage = errorData.error_description || errorData.error;
}
} catch {
// Use default error message if JSON parsing fails
}
throw new Error(errorMessage);
}

const data: DeviceCodeResponse = await response.json();
Expand Down

0 comments on commit 14c289f

Please sign in to comment.