-
Notifications
You must be signed in to change notification settings - Fork 98
fix: add missing error handling in OAuth token exchange and credential decryption #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -48,6 +48,12 @@ export const exchangeGoogleCode = async ({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!tokenRes.ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Error( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `Google token exchange failed: ${tokenRes.status} ${tokenRes.statusText}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+52
to
+53
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Error( | |
| `Google token exchange failed: ${tokenRes.status} ${tokenRes.statusText}`, | |
| const contentType = tokenRes.headers.get("content-type") ?? ""; | |
| let errorDetail: string | undefined; | |
| try { | |
| if (contentType.includes("application/json")) { | |
| const errorBody = (await tokenRes.json()) as { | |
| error?: string; | |
| error_description?: string; | |
| }; | |
| errorDetail = | |
| errorBody.error_description || | |
| errorBody.error || | |
| undefined; | |
| } else { | |
| const text = await tokenRes.text(); | |
| errorDetail = text || undefined; | |
| } | |
| } catch { | |
| // Ignore body parsing errors; fall back to generic message below. | |
| } | |
| const baseMessage = `Google token exchange failed: ${tokenRes.status} ${tokenRes.statusText}`; | |
| throw new Error( | |
| errorDetail ? `${baseMessage} - ${errorDetail}` : baseMessage, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On non-OK responses, this throws using only status/statusText and skips reading the response body. GitHub’s token endpoint often returns a JSON body with useful
error/error_descriptioneven when the status isn’t 2xx; consider including the parsed JSON (when available) or at leastawait tokenRes.text()in the thrown error to improve diagnostics.