Repository navigation
fix(storage): expose service error code on StorageApiError - #2537
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughSummary by CodeRabbit
Walkthrough
Assessment against linked issues
Possibly related PRs
Suggested labels: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
mandarini
left a comment
There was a problem hiding this comment.
Hi @thribhuvan003, thank you so much for contributing to Supabase! 💚
This is exactly the right fix. You landed on the correct field: the Storage service always sends the documented code (NoSuchKey, AccessDenied, and so on) as code in the response body, and the SDK was quietly dropping it because statusCode took precedence. Passing err.code through onto a dedicated code property, and including it in toJSON(), is precisely what we want.
Two small things before we merge, neither blocking:
-
In the new fetch test the mock body is
{ code: 'NoSuchKey', message: 'Object not found' }with nostatusCode. That happens to exercise the legacy fallback wherestatusCodealso becomes'NoSuchKey', which is not what a real server sends. The real payload always includes both, like{ statusCode: '404', code: 'NoSuchKey', message: '...' }. Could you tweak the fixture to includestatusCodeso it mirrors reality? The assertion oncodestays the same. -
Optional, but nice to have: a small integration test that downloads a missing object and asserts
error.code, so we lock in that the server really does send what we are reading. Happy to merge without it if you would rather keep the PR tight.
Thank you again for the clean, focused patch and for the tests that actually fail without the change. Contributions like this are what keep the SDK healthy.
@supabase/auth-js
@supabase/functions-js
@supabase/postgrest-js
@supabase/realtime-js
@supabase/storage-js
@supabase/supabase-js
commit: |
|
thanks @mandarini, that means a lot 💚 done on (1) — the fetch fixture now sends on (2): i'd like to add it, but i can't run the storage docker stack in my dev env to verify the exact |
|
Really appreciate the follow-up, and you asked exactly the right question in (2): what Here's why: the server generates Your instinct not to push an integration assertion you hadn't seen pass was correct, it would have failed, and that's what surfaced this. The client patch is the right shape, but it can't deliver until the server includes |
|
@thribhuvan003 good news btw, storage team added it on their timeline! so once they make a PR i will link it here, and once PR is merged and released, we can move on with your PR! |
|
amazing, thank you 🙌 no rush at all on my end — i'll watch for the storage team's PR and align mine once it lands. |
|
@thribhuvan003 this is now shipped on the storage server! |
1c9c7c0 to
834f93f
Compare
|
Thanks @mandarini — great news, and thank you for driving the server-side change! I've rebased onto the latest master, and the client already reads the newly shipped One thing on the SDK Compliance check: it flags |
Registers a new area-level feature for exposing the machine-readable service error code (e.g. NoSuchKey, AccessDenied) on thrown storage errors, covering both file and vector bucket operations. Needed to map StorageApiError.code / StorageVectorsApiError.code being added in supabase/supabase-js#2537.
Registers a new area-level feature for exposing the machine-readable service error code (e.g. NoSuchKey, AccessDenied) on thrown storage errors, covering both file and vector bucket operations. Needed to map StorageApiError.code / StorageVectorsApiError.code being added in supabase/supabase-js#2537.
834f93f to
691cf89
Compare
This PR updates `@supabase/supabase-js` to v2.112.3. **Source**: manual --- ## Release Notes ## v2.112.3 ## 2.112.3 (2026-08-11) ### 🩹 Fixes - **supabase:** add trace context headers to canonical CORS allow-list ([#2603](supabase/supabase-js#2603)) - **supabase:** improve trace propagation sampling and diagnostics ([#2604](supabase/supabase-js#2604)) ### ❤️ Thank You - Katerina Skroumpelou @mandarini ## v2.112.2 ## 2.112.2 (2026-08-06) ### 🩹 Fixes - **realtime:** prevent duplicate on bindings ([#2594](supabase/supabase-js#2594)) - **realtime:** clear stale join payload on sign-out ([#2597](supabase/supabase-js#2597)) ### ❤️ Thank You - Filipe Cabaço @filipecabaco - Vaibhav @7ttp ## v2.112.1 ## 2.112.1 (2026-08-05) ### 🩹 Fixes - **auth:** preserve 5xx error message ([#2587](supabase/supabase-js#2587)) - **realtime:** ensure setAuth doesn't disable token refresh ([#2592](supabase/supabase-js#2592)) ### ❤️ Thank You - Eduardo Gurgel - Vaibhav @7ttp ## v2.112.0 ## 2.112.0 (2026-08-03) ### 🚀 Features - **supabase:** move OpenTelemetry tracing to opt-in /tracing subpath ([#2583](supabase/supabase-js#2583)) ### 🩹 Fixes - **auth:** accept uppercase UUIDs in validateUUID ([#2467](supabase/supabase-js#2467)) - **postgrest:** honour throwOnError when maybeSingle finds multiple rows ([#2580](supabase/supabase-js#2580)) - **storage:** resolve createSignedUrls return type mismatch ([#2474](supabase/supabase-js#2474)) - **storage:** expose service error code on StorageApiError ([#2537](supabase/supabase-js#2537)) - **supabase:** forward db retry option ([#2571](supabase/supabase-js#2571)) ### ❤️ Thank You - Anubhav Anand @i-anubhav-anand - Gourab Singha @gourabsingha1 - Juhef @juheff - Katerina Skroumpelou @mandarini - Thribhuvan - Vaibhav @7ttp - Zuhef Ahmed @Zuhef This PR was created automatically. Co-authored-by: supabase-workflow-trigger[bot] <266661614+supabase-workflow-trigger[bot]@users.noreply.github.com>
This PR updates @supabase/*-js libraries to version 2.112.3. **Source**: manual **Changes**: - Updated @supabase/supabase-js to 2.112.3 - Updated @supabase/auth-js to 2.112.3 - Updated @supabase/realtime-js to 2.112.3 - Updated @supabase/postgest-js to 2.112.3 - Refreshed pnpm-lock.yaml --- ## Release Notes ## v2.112.3 ## 2.112.3 (2026-08-11) ### 🩹 Fixes - **supabase:** add trace context headers to canonical CORS allow-list ([#2603](supabase/supabase-js#2603)) - **supabase:** improve trace propagation sampling and diagnostics ([#2604](supabase/supabase-js#2604)) ### ❤️ Thank You - Katerina Skroumpelou @mandarini ## v2.112.2 ## 2.112.2 (2026-08-06) ### 🩹 Fixes - **realtime:** prevent duplicate on bindings ([#2594](supabase/supabase-js#2594)) - **realtime:** clear stale join payload on sign-out ([#2597](supabase/supabase-js#2597)) ### ❤️ Thank You - Filipe Cabaço @filipecabaco - Vaibhav @7ttp ## v2.112.1 ## 2.112.1 (2026-08-05) ### 🩹 Fixes - **auth:** preserve 5xx error message ([#2587](supabase/supabase-js#2587)) - **realtime:** ensure setAuth doesn't disable token refresh ([#2592](supabase/supabase-js#2592)) ### ❤️ Thank You - Eduardo Gurgel - Vaibhav @7ttp ## v2.112.0 ## 2.112.0 (2026-08-03) ### 🚀 Features - **supabase:** move OpenTelemetry tracing to opt-in /tracing subpath ([#2583](supabase/supabase-js#2583)) ### 🩹 Fixes - **auth:** accept uppercase UUIDs in validateUUID ([#2467](supabase/supabase-js#2467)) - **postgrest:** honour throwOnError when maybeSingle finds multiple rows ([#2580](supabase/supabase-js#2580)) - **storage:** resolve createSignedUrls return type mismatch ([#2474](supabase/supabase-js#2474)) - **storage:** expose service error code on StorageApiError ([#2537](supabase/supabase-js#2537)) - **supabase:** forward db retry option ([#2571](supabase/supabase-js#2571)) ### ❤️ Thank You - Anubhav Anand @i-anubhav-anand - Gourab Singha @gourabsingha1 - Juhef @juheff - Katerina Skroumpelou @mandarini - Thribhuvan - Vaibhav @7ttp - Zuhef Ahmed @Zuhef ## v2.111.0 ## 2.111.0 (2026-07-28) ### 🚀 Features - **auth:** store PKCE verifiers in per-flow slots to survive overlapping flows ([#2569](supabase/supabase-js#2569)) ### ❤️ Thank You - Katerina Skroumpelou @mandarini This PR was created automatically. Co-authored-by: supabase-workflow-trigger[bot] <266661614+supabase-workflow-trigger[bot]@users.noreply.github.com>
Closes #1650. SDK-1426. Stacked on #1647, which is where `StorageException` becomes a `SupabaseException` and its `fromJson` gets its defensive field reads. Review that one first; the diff here is only the last commit. Storage answers a failed request with a body like: ```json { "statusCode": "404", "error": "not_found", "code": "NoSuchKey", "message": "Object not found" } ``` `code` is the [documented storage error code](https://supabase.com/docs/guides/storage/debugging/error-codes) and is what STORAGE-629 added to the server's error schema. supabase-js picked it up in [supabase/supabase-js#2537](supabase/supabase-js#2537) as a new `code` field on `StorageApiError`. ## The Dart shape A second `code` field alongside `errorCode` would give storage two overlapping identifiers and undo the point of the unified exception in this stack, so `code` goes into `SupabaseException.errorCode` instead. That field is already documented as "service specific identifier for the error", which is exactly what this is. `error` stays as the fallback for servers that predate the schema change. It is not a good primary source: against a local stack, the same field is `not_found` for a missing object and `Bucket not found` for a missing bucket, so it carries a plain sentence about as often as an identifier. `code` does not have that problem. ```dart try { await supabase.storage.from('avatars').download('missing.png'); } on StorageException catch (error) { if (error.errorCode == 'NoSuchKey') { // ... } } ``` The example in `SupabaseException.errorCode`'s doc comment moves from `not_found` to `NoSuchKey` to match what storage now yields. ## Testing `types_test.dart` covers the three `fromJson` branches (`code` wins over `error`, `error` as fallback, null when the body has neither). `basic_test.dart` covers the same through a real request, so the value survives the fetch layer rather than only the factory. `melos analyze` and `melos format` clean. The full `storage_client` suite passes against a local stack (220 tests), as does `supabase_common`. ## Compliance matrix `storage.errors.error_codes` → `implemented`. Symbol, drift and schema checks pass locally. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Storage errors now consistently preserve service-provided error codes. - Added fallback handling when the primary error-code field is unavailable. - Download errors now retain the correct status code and message. - **Documentation** - Updated storage error-code examples to reflect current identifiers. - **Tests** - Added coverage for error-code parsing, fallback behavior, missing codes, status codes, and messages. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
 <h3>Snyk has created this PR to upgrade @supabase/supabase-js from 2.112.0 to 2.112.2.</h3> :information_source: Keep your dependencies up-to-date. This makes it easier to fix existing vulnerabilities and to more quickly identify and fix newly disclosed vulnerabilities when they affect your project. <hr/> - The recommended version is **6 versions** ahead of your current version. - The recommended version was released **21 days ago**. #### Breaking Change Risk  > **Notice:** This assessment is enhanced by AI. <details> <summary><b>Release notes</b></summary> <br/> <details> <summary>Package name: <b>@supabase/supabase-js</b></summary> <ul> <li> <b>2.112.2</b> - <a href="https://redirect.github.com/supabase/supabase-js/releases/tag/v2.112.2">2026-08-06</a></br><h2>2.112.2 (2026-08-06)</h2> <h3>🩹 Fixes</h3> <ul> <li><strong>realtime:</strong> prevent duplicate on bindings (<a href="https://redirect.github.com/supabase/supabase-js/pull/2594" data-hovercard-type="pull_request" data-hovercard-url="/supabase/supabase-js/pull/2594/hovercard">#2594</a>)</li> <li><strong>realtime:</strong> clear stale join payload on sign-out (<a href="https://redirect.github.com/supabase/supabase-js/pull/2597" data-hovercard-type="pull_request" data-hovercard-url="/supabase/supabase-js/pull/2597/hovercard">#2597</a>)</li> </ul> <h3>❤️ Thank You</h3> <ul> <li>Filipe Cabaço <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/filipecabaco/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://redirect.github.com/filipecabaco">@ filipecabaco</a></li> <li>Vaibhav <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/7ttp/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://redirect.github.com/7ttp">@ 7ttp</a></li> </ul> </li> <li> <b>2.112.2-canary.1</b> - <a href="https://redirect.github.com/supabase/supabase-js/releases/tag/v2.112.2-canary.1">2026-08-06</a></br><h2>2.112.2-canary.1 (2026-08-06)</h2> <h3>🩹 Fixes</h3> <ul> <li><strong>realtime:</strong> clear stale join payload on sign-out (<a href="https://redirect.github.com/supabase/supabase-js/pull/2597" data-hovercard-type="pull_request" data-hovercard-url="/supabase/supabase-js/pull/2597/hovercard">#2597</a>)</li> </ul> <h3>❤️ Thank You</h3> <ul> <li>Vaibhav <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/7ttp/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://redirect.github.com/7ttp">@ 7ttp</a></li> </ul> </li> <li> <b>2.112.2-canary.0</b> - <a href="https://redirect.github.com/supabase/supabase-js/releases/tag/v2.112.2-canary.0">2026-08-06</a></br><h2>2.112.2-canary.0 (2026-08-06)</h2> <h3>🩹 Fixes</h3> <ul> <li><strong>realtime:</strong> prevent duplicate on bindings (<a href="https://redirect.github.com/supabase/supabase-js/pull/2594" data-hovercard-type="pull_request" data-hovercard-url="/supabase/supabase-js/pull/2594/hovercard">#2594</a>)</li> </ul> <h3>❤️ Thank You</h3> <ul> <li>Filipe Cabaço <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/filipecabaco/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://redirect.github.com/filipecabaco">@ filipecabaco</a></li> </ul> </li> <li> <b>2.112.1</b> - <a href="https://redirect.github.com/supabase/supabase-js/releases/tag/v2.112.1">2026-08-05</a></br><h2>2.112.1 (2026-08-05)</h2> <h3>🩹 Fixes</h3> <ul> <li><strong>auth:</strong> preserve 5xx error message (<a href="https://redirect.github.com/supabase/supabase-js/pull/2587" data-hovercard-type="pull_request" data-hovercard-url="/supabase/supabase-js/pull/2587/hovercard">#2587</a>)</li> <li><strong>realtime:</strong> ensure setAuth doesn't disable token refresh (<a href="https://redirect.github.com/supabase/supabase-js/pull/2592" data-hovercard-type="pull_request" data-hovercard-url="/supabase/supabase-js/pull/2592/hovercard">#2592</a>)</li> </ul> <h3>❤️ Thank You</h3> <ul> <li>Eduardo Gurgel</li> <li>Vaibhav <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/7ttp/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://redirect.github.com/7ttp">@ 7ttp</a></li> </ul> </li> <li> <b>2.112.1-canary.1</b> - <a href="https://redirect.github.com/supabase/supabase-js/releases/tag/v2.112.1-canary.1">2026-08-05</a></br><h2>2.112.1-canary.1 (2026-08-05)</h2> <h3>🩹 Fixes</h3> <ul> <li><strong>realtime:</strong> ensure setAuth doesn't disable token refresh (<a href="https://redirect.github.com/supabase/supabase-js/pull/2592" data-hovercard-type="pull_request" data-hovercard-url="/supabase/supabase-js/pull/2592/hovercard">#2592</a>)</li> </ul> <h3>❤️ Thank You</h3> <ul> <li>Eduardo Gurgel</li> </ul> </li> <li> <b>2.112.1-canary.0</b> - <a href="https://redirect.github.com/supabase/supabase-js/releases/tag/v2.112.1-canary.0">2026-08-03</a></br><h2>2.112.1-canary.0 (2026-08-03)</h2> <h3>🩹 Fixes</h3> <ul> <li><strong>auth:</strong> preserve 5xx error message (<a href="https://redirect.github.com/supabase/supabase-js/pull/2587" data-hovercard-type="pull_request" data-hovercard-url="/supabase/supabase-js/pull/2587/hovercard">#2587</a>)</li> </ul> <h3>❤️ Thank You</h3> <ul> <li>Vaibhav <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/7ttp/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://redirect.github.com/7ttp">@ 7ttp</a></li> </ul> </li> <li> <b>2.112.0</b> - <a href="https://redirect.github.com/supabase/supabase-js/releases/tag/v2.112.0">2026-08-03</a></br><h2>2.112.0 (2026-08-03)</h2> <h3>🚀 Features</h3> <ul> <li><strong>supabase:</strong> move OpenTelemetry tracing to opt-in /tracing subpath (<a href="https://redirect.github.com/supabase/supabase-js/pull/2583" data-hovercard-type="pull_request" data-hovercard-url="/supabase/supabase-js/pull/2583/hovercard">#2583</a>)</li> </ul> <h3>🩹 Fixes</h3> <ul> <li><strong>auth:</strong> accept uppercase UUIDs in validateUUID (<a href="https://redirect.github.com/supabase/supabase-js/pull/2467" data-hovercard-type="pull_request" data-hovercard-url="/supabase/supabase-js/pull/2467/hovercard">#2467</a>)</li> <li><strong>postgrest:</strong> honour throwOnError when maybeSingle finds multiple rows (<a href="https://redirect.github.com/supabase/supabase-js/pull/2580" data-hovercard-type="pull_request" data-hovercard-url="/supabase/supabase-js/pull/2580/hovercard">#2580</a>)</li> <li><strong>storage:</strong> resolve createSignedUrls return type mismatch (<a href="https://redirect.github.com/supabase/supabase-js/pull/2474" data-hovercard-type="pull_request" data-hovercard-url="/supabase/supabase-js/pull/2474/hovercard">#2474</a>)</li> <li><strong>storage:</strong> expose service error code on StorageApiError (<a href="https://redirect.github.com/supabase/supabase-js/pull/2537" data-hovercard-type="pull_request" data-hovercard-url="/supabase/supabase-js/pull/2537/hovercard">#2537</a>)</li> <li><strong>supabase:</strong> forward db retry option (<a href="https://redirect.github.com/supabase/supabase-js/pull/2571" data-hovercard-type="pull_request" data-hovercard-url="/supabase/supabase-js/pull/2571/hovercard">#2571</a>)</li> </ul> <h3>❤️ Thank You</h3> <ul> <li>Anubhav Anand <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/i-anubhav-anand/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://redirect.github.com/i-anubhav-anand">@ i-anubhav-anand</a></li> <li>Gourab Singha <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gourabsingha1/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://redirect.github.com/gourabsingha1">@ gourabsingha1</a></li> <li>Juhef @ juheff</li> <li>Katerina Skroumpelou <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/mandarini/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://redirect.github.com/mandarini">@ mandarini</a></li> <li>Thribhuvan</li> <li>Vaibhav <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/7ttp/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://redirect.github.com/7ttp">@ 7ttp</a></li> <li>Zuhef Ahmed <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/Zuhef/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://redirect.github.com/Zuhef">@ Zuhef</a></li> </ul> </li> </ul> from <a href="https://redirect.github.com/supabase/supabase-js/releases">@supabase/supabase-js GitHub release notes</a> </details> </details> --- > [!IMPORTANT] > > - Check the changes in this PR to ensure they won't cause issues with your project. > - This PR was automatically created by Snyk using the credentials of a real user. --- **Note:** _You are seeing this because you or someone else with access to this repository has authorized Snyk to open upgrade PRs._ **For more information:** <img src="https://api.segment.io/v1/pixel/track?data=eyJ3cml0ZUtleSI6ImZha2Uta2V5IiwiYW5vbnltb3VzSWQiOiI3MTA5YzliNi04YjY0LTRlOGYtYjI1My03MGY3MGJmOTZkNWQiLCJldmVudCI6IlBSIHZpZXdlZCIsInByb3BlcnRpZXMiOnsicHJJZCI6IjcxMDljOWI2LThiNjQtNGU4Zi1iMjUzLTcwZjcwYmY5NmQ1ZCJ9fQ==" width="0" height="0"/> > - 🧐 [View latest project report](https://app.eu.snyk.io/org/antigravity-awesome-skills-default/project/e1f199d3-0a16-4ac7-a9a1-528e774fc41f?utm_source=github&utm_medium=referral&page=upgrade-pr) > - 📜 [Customise PR templates](https://docs.snyk.io/scan-using-snyk/pull-requests/snyk-fix-pull-or-merge-requests/customize-pr-templates?utm_source=&utm_content=fix-pr-template) > - 🛠 [Adjust upgrade PR settings](https://app.eu.snyk.io/org/antigravity-awesome-skills-default/project/e1f199d3-0a16-4ac7-a9a1-528e774fc41f/settings/integration?utm_source=github&utm_medium=referral&page=upgrade-pr) > - 🔕 [Ignore this dependency or unsubscribe from future upgrade PRs](https://app.eu.snyk.io/org/antigravity-awesome-skills-default/project/e1f199d3-0a16-4ac7-a9a1-528e774fc41f/settings/integration?pkg=@supabase/supabase-js&utm_source=github&utm_medium=referral&page=upgrade-pr#auto-dep-upgrades) [//]: # 'snyk:metadata:{"breakingChangeRiskLevel":"low","FF_showPullRequestBreakingChanges":true,"FF_showPullRequestBreakingChangesWebSearch":false,"customTemplate":{"variablesUsed":[],"fieldsUsed":[]},"dependencies":[{"name":"@supabase/supabase-js","from":"2.112.0","to":"2.112.2"}],"env":"prod","hasFixes":false,"isBreakingChange":false,"isMajorUpgrade":false,"issuesToFix":[],"prId":"7109c9b6-8b64-4e8f-b253-70f70bf96d5d","prPublicId":"7109c9b6-8b64-4e8f-b253-70f70bf96d5d","packageManager":"npm","priorityScoreList":[],"projectPublicId":"e1f199d3-0a16-4ac7-a9a1-528e774fc41f","projectUrl":"https://app.eu.snyk.io/org/antigravity-awesome-skills-default/project/e1f199d3-0a16-4ac7-a9a1-528e774fc41f?utm_source=github&utm_medium=referral&page=upgrade-pr","prType":"upgrade","templateFieldSources":{"branchName":"default","commitMessage":"default","description":"default","title":"default"},"templateVariants":[],"type":"auto","upgrade":[],"upgradeInfo":{"versionsDiff":6,"publishedDate":"2026-08-06T13:36:57.425Z"},"vulns":[]}'
🔍 Description
What changed?
StorageApiErrornow carries the service error code (NoSuchKey,AccessDenied,ResourceAlreadyExists, etc.) on a dedicatedcodeproperty, and includes it intoJSON().The response body already contains this in
err.code—handleErrorinstorage-js/src/lib/common/fetch.tswas only using it as a fallback forstatusCodeand otherwise dropping it, so it never reached the error object. Now it is passed through to the new field.statusCodeis unchanged.Why was this change needed?
The Storage error-codes docs tell you to branch on codes like
AccessDenied/NoSuchKey, but the thrownStorageApiErrornever exposed them — it only hadstatusandstatusCode— so that pattern was impossible to implement without parsing the message string. This closes that gap.Closes #2536
📸 Screenshots/Examples
🔄 Breaking changes
Additive only — a new optional constructor arg and a new field.
codeisundefinedwhen the response has no code, and existingstatus/statusCodebehaviour is untouched.📋 Checklist
<type>(<scope>): <description>pnpm nx formatto ensure consistent code formatting📝 Additional notes
Added unit tests in both
errors.test.ts(thecodefield +toJSON) andfetch.test.ts(that acodein the response body reaches the error) — they fail without the change and pass with it.