Skip to content
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

Surface all App Check errors in public getToken() method #8842

Merged
merged 3 commits into from
Mar 17, 2025

Conversation

hsubox76
Copy link
Contributor

@hsubox76 hsubox76 commented Mar 13, 2025

The two main changes here are

  • throw "internalError" (background: Fix App Check timer issues #6617) in the public-facing getToken() method. Errors here should not block 2P calls to App Check (internal calls from Auth, Firestore, etc)
  • Distinguish between an initial network error that causes throttling, and an error thrown by attempting to make a call while a throttle is in effect

I've also decided to stop logging getToken errors with console.error - these should all be thrown by the public getToken() now, and the internal products calling getToken internally (Auth, Firestore, etc.) have access to the error message in a property of AppCheckTokenResult which they can log in the format they choose.

Fixes #8822

Copy link

changeset-bot bot commented Mar 13, 2025

🦋 Changeset detected

Latest commit: f5a1e4d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@firebase/app-check Patch
@firebase/app-check-compat Patch
firebase Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Mar 13, 2025

Size Report 1

Affected Products

  • @firebase/app-check

    TypeBase (feb2c9d)Merge (76179c8)Diff
    browser26.4 kB26.7 kB+304 B (+1.2%)
    main27.4 kB27.7 kB+304 B (+1.1%)
    module26.4 kB26.7 kB+304 B (+1.2%)
  • bundle

    TypeBase (feb2c9d)Merge (76179c8)Diff
    app-check (CustomProvider)37.6 kB37.8 kB+238 B (+0.6%)
    app-check (ReCaptchaEnterpriseProvider)40.1 kB40.3 kB+245 B (+0.6%)
    app-check (ReCaptchaV3Provider)40.0 kB40.3 kB+245 B (+0.6%)
  • firebase

    TypeBase (feb2c9d)Merge (76179c8)Diff
    firebase-app-check-compat.js22.7 kB22.9 kB+230 B (+1.0%)
    firebase-app-check.js25.0 kB25.3 kB+230 B (+0.9%)
    firebase-compat.js793 kB793 kB+230 B (+0.0%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/TFGpX62Q69.html

@@ -54,7 +55,8 @@ const ERRORS: ErrorMap<AppCheckError> = {
[AppCheckError.STORAGE_WRITE]:
'Error thrown when writing to storage. Original error: {$originalErrorMessage}.',
[AppCheckError.RECAPTCHA_ERROR]: 'ReCAPTCHA error.',
[AppCheckError.THROTTLED]: `Requests throttled due to {$httpStatus} error. Attempts allowed again after {$time}`
[AppCheckError.INITIAL_THROTTLE]: `{$httpStatus} error. Attempts allowed again after {$time}`,
[AppCheckError.THROTTLED]: `Requests throttled due to previous {$httpStatus} error. Attempts allowed again after {$time}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, these should be transposed to match the order in ErrorParams and AppCheckError.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flipped it around the other way on the other two since logically I guess the "initial throttle" should come first.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Mar 13, 2025

Size Analysis Report 1

Affected Products

  • @firebase/app-check

    • CustomProvider

      Size

      TypeBase (feb2c9d)Merge (76179c8)Diff
      size7.72 kB7.87 kB+147 B (+1.9%)
      size-with-ext-deps26.4 kB26.5 kB+147 B (+0.6%)
    • ReCaptchaEnterpriseProvider

      Size

      TypeBase (feb2c9d)Merge (76179c8)Diff
      size11.4 kB11.6 kB+154 B (+1.4%)
      size-with-ext-deps29.9 kB30.1 kB+154 B (+0.5%)
    • ReCaptchaV3Provider

      Size

      TypeBase (feb2c9d)Merge (76179c8)Diff
      size11.4 kB11.5 kB+154 B (+1.4%)
      size-with-ext-deps29.9 kB30.0 kB+154 B (+0.5%)
    • getLimitedUseToken

      Size

      TypeBase (feb2c9d)Merge (76179c8)Diff
      size7.29 kB7.44 kB+147 B (+2.0%)
      size-with-ext-deps25.5 kB25.6 kB+147 B (+0.6%)
    • getToken

      Size

      TypeBase (feb2c9d)Merge (76179c8)Diff
      size7.35 kB7.54 kB+189 B (+2.6%)
      size-with-ext-deps25.5 kB25.7 kB+189 B (+0.7%)
    • initializeAppCheck

      Size

      TypeBase (feb2c9d)Merge (76179c8)Diff
      size11.3 kB11.5 kB+196 B (+1.7%)
      size-with-ext-deps36.6 kB36.8 kB+196 B (+0.5%)
    • onTokenChanged

      Size

      TypeBase (feb2c9d)Merge (76179c8)Diff
      size7.45 kB7.59 kB+147 B (+2.0%)
      size-with-ext-deps25.6 kB25.8 kB+147 B (+0.6%)
    • setTokenAutoRefreshEnabled

      Size

      TypeBase (feb2c9d)Merge (76179c8)Diff
      size7.44 kB7.59 kB+147 B (+2.0%)
      size-with-ext-deps25.6 kB25.8 kB+147 B (+0.6%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/xAdZmihDKL.html

@hsubox76 hsubox76 marked this pull request as ready for review March 17, 2025 22:52
@hsubox76 hsubox76 requested review from a team as code owners March 17, 2025 22:52
@hsubox76 hsubox76 merged commit 95b4fc6 into main Mar 17, 2025
36 of 37 checks passed
@hsubox76 hsubox76 deleted the ch-appcheck-errors branch March 17, 2025 23:05
@google-oss-bot google-oss-bot mentioned this pull request Mar 18, 2025
@nermeen-mattar
Copy link

@hsubox76 Thank you for addressing this promptly. May I ask when we can expect this fix to be released?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

app-check: getToken with forceRefresh:true swallows errors and returns cached token
4 participants