-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Better handling for GFE errors #10313
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
base: main
Are you sure you want to change the base?
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,8 +16,8 @@ | |||||
|
|
||||||
| // Using import would require resolveJsonModule, which seems to break the | ||||||
| // build/output format. | ||||||
| const pkg = require("../package.json"); | ||||||
|
Check warning on line 19 in src/apiv2.ts
|
||||||
| const CLI_VERSION: string = pkg.version; | ||||||
|
Check warning on line 20 in src/apiv2.ts
|
||||||
|
|
||||||
| export const standardHeaders: () => Record<string, string> = () => { | ||||||
| const agent = detectAIAgent(); | ||||||
|
|
@@ -134,7 +134,7 @@ | |||||
|
|
||||||
| /** | ||||||
| * Gets a singleton access token | ||||||
| * @returns An access token | ||||||
| */ | ||||||
| export async function getAccessToken(): Promise<string> { | ||||||
| const valid = auth.haveValidTokens(refreshToken, []); | ||||||
|
|
@@ -239,7 +239,7 @@ | |||||
| * Makes a request as specified by the options. | ||||||
| * By default, this will: | ||||||
| * - use content-type: application/json | ||||||
| * - assume the HTTP GET method | ||||||
| * | ||||||
| * @example | ||||||
| * const res = apiv2.request<ResourceType>({ | ||||||
|
|
@@ -466,6 +466,9 @@ | |||||
|
|
||||||
| if (options.responseType === "json") { | ||||||
| const text = await res.text(); | ||||||
| if (isGfeError(text)) { | ||||||
| throw new FirebaseError("the service you are calling doesnt exist or is misconfigured", { status: res.status }); | ||||||
|
Check failure on line 470 in src/apiv2.ts
|
||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message contains a typo ("doesnt") and should be properly capitalized for consistency with other user-facing errors in the codebase.
Suggested change
References
|
||||||
| } | ||||||
| // Some responses, such as 204 and occasionally 202s don't have | ||||||
| // any content. We can't just rely on response code (202 may have conent) | ||||||
| // and unfortuantely res.length is unreliable (many requests return zero). | ||||||
|
|
@@ -580,6 +583,10 @@ | |||||
| return u.protocol === "http:"; | ||||||
| } | ||||||
|
|
||||||
| function isGfeError(text: string): boolean { | ||||||
| return text.includes("That’s all we know.") && text.includes("<!DOCTYPE html>"); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a specific smart quote (
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| function bodyToString(body: unknown): string { | ||||||
| if (isStream(body)) { | ||||||
| // Don't attempt to read any stream type, in case the caller needs it. | ||||||
|
|
||||||
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.
Updating the test expectation to match the corrected error message.