fix(search): normalize bare-array response from POST /search#650
Open
kevinheneveld wants to merge 1 commit into
Open
fix(search): normalize bare-array response from POST /search#650kevinheneveld wants to merge 1 commit into
kevinheneveld wants to merge 1 commit into
Conversation
The unified search endpoint returns a flat array of Audible-shaped results
(see SearchController.cs: `return Ok(flatMapped)`), but the FE service method
`searchAudibleByTitleAndAuthor` typed the response as the wrapped
`{ totalResults, results }` envelope. When the array shape arrived the
method treated it as an object without `.results` and silently dropped
every hit — callers saw "no matches" even when IntelligentSearch had
actually found one.
Normalize both shapes:
- Bare array → `{ totalResults: resp.length, results: resp }`
- Wrapped envelope → returned as-is
- null / undefined → empty envelope
Three tests cover the array, wrapped, and null cases.
This is the latent bug the metadata-backfill modal in the next commit
exposes most aggressively (every search is title+author), but the issue
affects any current or future caller of `searchAudibleByTitleAndAuthor`.
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.
Summary
searchAudibleByTitleAndAuthorsilently dropped every result when the search endpoint returned a bare array. The unifiedPOST /searchendpoint returns a flat array of Audible-shaped result objects (SearchControllerdoesreturn Ok(flatMapped)), but the FE service method typed the response as the wrapped{ totalResults, results }envelope and read.resultsoff it. When the array shape arrived it had no.results, so the method returned zero hits and callers saw "no matches" even though IntelligentSearch had actually found one. The method now normalizes both response shapes.Why this matters
Any feature that searches Audible by title + author is affected — the call can find a match server-side and the UI still reports nothing. It's shape-dependent, so it surfaces inconsistently and is easy to misread as "Audible just didn't have it."
Implementation notes
fe/src/services/api.ts—searchAudibleByTitleAndAuthoronly.{ totalResults: resp.length, results: resp }{ totalResults, results }envelope → returned as-isnull/undefined→ empty envelope ({ totalResults: 0, results: [] })Test plan
npx vitest run src/__tests__/api.advancedSearch.spec.ts— 5/5 passing (new; covers array, wrapped, and null cases).npm run type-check— clean.