How to catch "uncaught" errors in Vue Instant Search

Hello,

I am using secured API keys and setting the keys to expire after 30mins (using validUntil param).

After 30 minutes has passed, Algolia/Instant Search starts returning this error

{name: "AlgoliaSearchError", 
message: ""validUntil" parameter expired (less than current date)", 
debugData: Array(1), 
statusCode: 400, 
stack: "AlgoliaSearchError: "validUntil" parameter expired…rch@3.33.0/dist/algoliasearchLite.min.js:2:21126)"}

Which is great! But how do I actually “catch” this error so our system can confirm the user still has permission?

Right now it’s just “uncaught” according to the chrome console.

Thanks!

Hello, thanks for reaching out to us.

We currently do not provide a proper way to replace the key at the moment.
However, you can wrap searchClient to catch the exception and update the searchClient with a new secured api key.

Here’s the example.
If you change the apiKey on the CodeSandbox to something like “abc”, it will throw an exception and you’ll see how it’s caught in line 85.

I hope this helps.

Please let us know if you have further question.
Thanks!

1 Like

Beautiful!! This works perfectly!

Thanks so much for creating the example code. It helped a ton!

Glad to hear that.
Have a nice day! :slight_smile: