typesense / typesense-js

JavaScript / TypeScript client for Typesense
https://typesense.org/docs/api
Apache License 2.0
393 stars 74 forks source link

Response Type is not thorough when making a multiSearch with an API key that has gone out of quota. #202

Closed CestDiego closed 1 week ago

CestDiego commented 3 months ago

Description

My OpenAI API Key seems to have exceeded it's current quota, and it returned the following instead of a SearchResponse type.

{
  results: [
    {
      code: 400,
      error: 'OpenAI API error: You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.'
    }
  ]
}

Steps to reproduce

Use an OpenAI Key that has exceeded quota.

Expected Behavior

There should be a union type for the SearchResponse type to have a type guard check for errors in the multiSearch.perform I was doing the following:

  const { results } = await TypesenseClient.multiSearch.perform<
    SearchSpacesHit[]
  >(searchRequest, commonSearchParams);
  console.log({ results });
  return {
    hits: results.length > 0 ? results[0].hits : [],
  };

Actual Behavior

I get no visibility of the errors in the types and so I gotta add a lot of linter-ignores to be able to check whether the first result of my search had an error code.

Metadata

Typesense Version: "typesense": "^1.8.2",

OS: MacOS

jasonbosco commented 3 months ago

Thank you for catching this.

I’d appreciate a PR, otherwise I can patch this next week.