Filip Nowacki
12/02/2024, 6:32 PMreact-instantsearch-nextjs
? I have a problem with cases when the typesense server is down. I'm trying to add support for error boundaries for the instant-search component but without any success 😞
The Axios error: "unhandledRejection: ref *2 AxiosError [AggregateError]..." crashes my entire nodejs server 😕Filip Nowacki
12/02/2024, 6:39 PMFilip Nowacki
12/02/2024, 6:39 PMJason Bosco
12/02/2024, 7:41 PMFanis Tharropoulos
12/02/2024, 9:34 PMFilip Nowacki
12/03/2024, 8:56 PMFilip Nowacki
12/08/2024, 7:21 PMFanis Tharropoulos
12/08/2024, 7:22 PMFilip Nowacki
12/08/2024, 7:23 PMFanis Tharropoulos
12/08/2024, 7:24 PMFanis Tharropoulos
12/09/2024, 10:19 AMFilip Nowacki
12/09/2024, 10:21 AMFanis Tharropoulos
12/09/2024, 11:07 AMFanis Tharropoulos
12/09/2024, 11:08 AMuseEffect
for the searchclient to verify that a healthcheck will pass and then try to serve the pageFilip Nowacki
12/09/2024, 11:30 AMFanis Tharropoulos
12/09/2024, 11:34 AMFilip Nowacki
12/09/2024, 11:36 AM// ...
try {
return (
<InstantSearchNext client={typesenseAdapter}>
// ..
</InstantSearchNext/>
)
} catch () {
// ...
}
Filip Nowacki
12/09/2024, 11:36 AMFanis Tharropoulos
12/09/2024, 11:43 AMexport default function Search() {
try {
await client.health.retrieve();
} catch (error) {
}
return (
<InstantSearchNext
searchClient={typesenseInstantsearchAdapter.searchClient}
indexName="games"
routing
future={{ preserveSharedStateOnUnmount: true }}
>
...
Filip Nowacki
12/09/2024, 11:44 AMFanis Tharropoulos
12/09/2024, 11:47 AM'use client';
import type { SearchClient } from 'instantsearch.js/es/types';
import { InstantSearchNext } from 'react-instantsearch-nextjs';
import TypesenseInstantSearchAdapter from 'typesense-instantsearch-adapter';
import { Client } from "typesense"
import { Hits } from './hits';
const adapter = new TypesenseInstantSearchAdapter({
server: {
nodes: [
{
host: 'wrong-host',
port: 8808,
protocol: 'http',
},
],
apiKey: 'xyz',
retryIntervalSeconds: 2,
},
additionalSearchParameters: {
per_page: 20,
query_by: 'name',
},
});
const client = new Client({
nodes: [
{
host: 'wrong-host',
port: 8808,
protocol: 'http',
},
],
apiKey: 'xyz',
connectionTimeoutSeconds: 2,
retryIntervalSeconds: 2,
})
export async function Search(): React.ReactNode {
try {
await client.health.retrieve();
}
catch {
console.error('Failed to connect to Typesense server');
return <div>Failed to connect to Typesense server</div>;
}
return (
<InstantSearchNext searchClient={adapter.searchClient as SearchClient} indexName="example_index" future={{ preserveSharedStateOnUnmount: true }}>
<Hits />
</InstantSearchNext>
);
}
This is the full file of search.tsx
that addresses this, hope this provides some help!