Skip to content

fix(storage): normalize 404 status checks in ServiceObject - #9922

Open
thiyaguk09 wants to merge 4 commits into
googleapis:mainfrom
thiyaguk09:fix/9889-service-object-404
Open

thiyaguk09 wants to merge 4 commits into
googleapis:mainfrom
thiyaguk09:fix/9889-service-object-404

Conversation

@thiyaguk09

Copy link
Copy Markdown
Contributor

Description

Normalizes HTTP status code checks across ServiceObject error handlers.

Impact

Fixes 404 handling regressions when using injected gaxios v7 auth clients.

Changes

  • Normalize HTTP status lookup in handwritten/storage/src/nodejs-common/service-object.ts using err.response?.status ?? err.status ?? err.code across delete, exists, and get (autoCreate 404 and onCreate 409 paths).
  • Guard callback-mode makeRequest error handlers in delete and getMetadata so callbacks are not invoked twice when StorageTransport.makeRequest both triggers its callback and rejects its returned promise, while still honoring ignoreNotFound if the promise rejects directly.

Testing

  • Updated async callback assertions in handwritten/storage/test/nodejs-common/service-object.ts to properly await completion via done.
  • Added unit tests covering err.code and err.response.status 404/409 normalization (with err.status === undefined) across delete({ ignoreNotFound: true }), exists(), and get({ autoCreate: true }).
  • Added an end-to-end test using StorageTransport with an injected authClient throwing gaxios v7-shaped 404 errors.

Fixes #9889

@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Nov 20, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates error handling in ServiceObject to robustly extract status codes (such as 404 and 409) from different error properties (err.response.status, err.status, or err.code), accommodating newer error shapes like those in Gaxios v7. It also prevents duplicate callback invocations and adds comprehensive unit tests. The review feedback correctly identifies several TypeScript compilation issues where properties are accessed on Error | null or unknown types, and suggests casting them to inline types with optional properties or to Error to ensure type safety.

@thiyaguk09
thiyaguk09 marked this pull request as ready for review November 20, 2026 08:25
@thiyaguk09
thiyaguk09 requested review from a team as code owners November 20, 2026 08:25

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

storage 9.0.0: delete({ ignoreNotFound }) and exists() reject with 404 when authClient comes from google-auth-library 11.1.0 (gaxios 7)

1 participant