Fix error handling when fetching fresh token in App Check #8829
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Fixes #8822
Issue:
When calling Firebase App Check’s getToken with
forceRefresh: truewhile a cached token exists, if fetching a new token failed, the error is stored ininternalErrorbut not returned or thrown to third-party callers. This leads to silent failures, causing the function to return a cached token instead of propagating the error.Impact:
This misleads the caller, who has no clue that the cached token was returned instead of a new one, preventing proper error handling. While the cached token may still be valid, forceRefresh is intended to fetch a new token, making this behavior inconsistent with its purpose.
Fix:
Now, when
forceRefreshistrue, the function returns both the error and token, ensuring failure is recognized.Why This is Correct:
This aligns with the expected behavior—if forceRefresh is requested, failures should be surfaced, not masked.
Benefit:
Allows third-party apps to handle errors properly and take proper corrective actions.