fix(resources): throw descriptive error when JSON:API data is empty or absent - #33
Merged
Merged
Conversation
…r absent
All 13 single-resource get* methods unwrapped response.data with
'Array.isArray(response.data) ? response.data[0] : response.data' and then
immediately read data.id, so an empty array or a body without data crashed
with an anonymous 'TypeError: Cannot read properties of undefined
(reading id)'. Route all 13 sites through a shared unwrapJsonApiData()
helper in json-api-mapper.ts that throws a descriptive AuvikError
('Auvik returned no <entity> for <id>') instead.
Part of the fleet sweep for unchecked response-envelope access, following
wyre-technology/halopsa-mcp#76 and wyre-technology/node-halopsa#59
(mirrors node-halopsa's centralized unwrapSingle).
github-actions Bot
pushed a commit
that referenced
this pull request
Aug 11, 2026
## [1.3.1](v1.3.0...v1.3.1) (2026-08-11) ### Bug Fixes * **resources:** throw descriptive error when JSON:API data is empty or absent ([#33](#33)) ([62cf835](62cf835)), closes [wyre-technology/halopsa-mcp#76](wyre-technology/halopsa-mcp#76) [wyre-technology/node-halopsa#59](wyre-technology/node-halopsa#59)
|
🎉 This PR is included in version 1.3.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Defect
All 13 single-resource
get*methods acrosssrc/resources/followed this pattern:When the API returns
{ data: [] }(data[0]isundefined) or a body with nodatakey at all, the next line crashes with an anonymous, undiagnosableTypeError: Cannot read properties of undefined (reading 'id')instead of a clear error. The comment inhttp.ts(lines 96-100) already documented this exact failure mode being triggered by content-type fallbacks returning{}.Part of the fleet sweep for unchecked response-envelope access, following wyre-technology/halopsa-mcp#76 / wyre-technology/node-halopsa#59.
Fix
Added a shared
unwrapJsonApiData<T>(response, context)helper tosrc/json-api-mapper.ts(mirroring node-halopsa's centralizedunwrapSingle) that throws a descriptiveAuvikError—Auvik returned no <entity> for <id> (response data was empty or missing)— when the entity is missing, and routed all 13 sites through it:alerts.ts—getHistorybilling.ts—getUsageDeviceinventory-configuration.ts—getinventory-device.ts—getInfo,getDetails,getWarranty,getLifecycleinventory-entity.ts—getNote,getAuditinventory-interface.ts—getInfoinventory-network.ts—getInfo,getDetailstenants.ts—getNo behavior change for valid
{ data: {...} }and{ data: [{...}] }shapes.Test plan
TDD: tests were written first and confirmed failing on the unguarded code (26 failures, all
TypeError: Cannot read properties of undefined), then the fix turned them green.tests/resources/unwrap-empty-data.test.tscovering all 13 methods x 4 shapes (52 tests):{ data: [] }throws descriptiveAuvikError,{}throws descriptiveAuvikError,{ data: {...} }resolves,{ data: [{...}] }resolves.npm run lint(tsc --noEmit) clean,npm run build(tsup incl. DTS) green.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is enabled.