-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(algolia): throw error if searchClient is missing (#1122)
* fix(algolia): throw error if searchClient is missing It's a synchronous error, but as this is only for debugging, i don't think it makes a big difference how the error is thrown. * move to invariant / clearer message * no test * not an option
- Loading branch information
Showing
4 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
18 changes: 15 additions & 3 deletions
18
packages/autocomplete-preset-algolia/src/requester/getAlgoliaResults.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
import { invariant } from '@algolia/autocomplete-shared'; | ||
|
||
import { createAlgoliaRequester } from './createAlgoliaRequester'; | ||
import { RequestParams } from './createRequester'; | ||
|
||
/** | ||
* Retrieves Algolia results from multiple indices. | ||
*/ | ||
export const getAlgoliaResults = createAlgoliaRequester({ | ||
transformResponse: (response) => response.hits, | ||
}); | ||
export function getAlgoliaResults<TTHit>(requestParams: RequestParams<TTHit>) { | ||
invariant( | ||
typeof requestParams.searchClient === 'object', | ||
'The `searchClient` parameter is required for getAlgoliaResults({ searchClient }).' | ||
); | ||
|
||
const requester = createAlgoliaRequester({ | ||
transformResponse: (response) => response.hits, | ||
}); | ||
|
||
return requester(requestParams); | ||
} |