nextjs typesense interment-search-hooks应用程序的错误处理

发布于 2025-02-11 10:20:23 字数 1679 浏览 1 评论 0 原文

目前,我正在尝试使用Firebase作为后端设置NextJS应用程序。因为firebase无法处理完整搜索,所以我想使用typesensens。他们提供了一个非常好的文档,如何进行设置:

对于Typesene,我已经为我所有3个环境设置了Docker容器(Docker typesensens 提供)。要从Docker请求信息,我使用 typesensensensensearch-Adapter -NPM软件包。在应用程序中,我具有不同的用户角色,因此并非每个人都能看到所有索引数据 - 因此,我使用范围搜索的搜索,该搜索可以通过用户登录时生成的apikey可以通过( scoped api key )。因此,Apikey根据用户和用户角色而变化。我当前的设置运行良好,并且搜索已经在工作。

我唯一的问题是,我无法捕获< instantsearch> -component正在投掷错误。例如,如果Docker离线或生成的Apikey无效。

我尝试了多个解决方案,但找不到适当的解决方案:

i找到了一个具有类似设置的代码和框。沙箱使用Algolia而不是类型义,但是弹出的错误是相同的: https://codesandbox.io/s/fib6jm?file=/app.tsx:1043-1056

  1. 访问app.tsx
  2. 行38
  3. 删除字符串
  4. 未熟悉,未指定的“错误”事件。 ([[对象对象])< / code>弹出了

如何捕获 /访问此错误以重新路由或显示错误屏幕?

Currently I'm trying to setup a nextjs app with firebase as backend. Because firebase cant handle a fulltext search, I want to use typesense. They provide a really nice documentation how to set it up: https://typesense.org/docs/guide/firebase-full-text-search.html

For typesene I already set up docker containers for all my 3 environment (the docker typesense provides). To request information back from the docker I use the typesense-instantsearch-adapter- npm Package. In the app I have different user roles, so not everyone can see all indexed data - therefore I use a scoped search which is possible through the apiKey I generate when the users logs in (scoped api key). The apiKey therefore is variable depending on the user and the user role. My current setup works fine and also the search is already working.

The only problem I have is, that I cannot catch the errors the <InstantSearch>-Component is throwing. For example if the docker is offline or if the generated apiKey is not valid.

I tried multiple solutions, but could not find a proper solution:

  • Error boundary around the component (react docu)
  • Error boundary npm package
  • Try/catch block around the component

I found a codesandbox that has a quit similar setup. The sandbox is using algolia instead of typesense, but the error that pops up is the same: https://codesandbox.io/s/fib6jm?file=/App.tsx:1043-1056

  1. Go to App.tsx
  2. line 38
  3. remove string
  4. Uncaught, unspecified "error" event. ([object Object]) pops up

How can I catch / access this error to reroute or show an error screen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文