generative-ai-js icon indicating copy to clipboard operation
generative-ai-js copied to clipboard

Update documentation to explain possible error codes from the model endpoint

Open ElYaiko opened this issue 1 year ago • 3 comments
trafficstars

Reading the docs I can't find a section where specifies the possible API error codes, in the examples/references it would be helpful to know what are the possible errors the API can return for error handling.

I hope this can be implemented, thanks!.

ElYaiko avatar Dec 17 '23 18:12 ElYaiko

Especially some info about how to handle the SAFETY errors. Right now I'm just filtering for the word SAFETY in the error response to handle that case as a warning. There must be a better way than this though.

I tried to do something like this using the typescript vs code hints, but it doesn't always work.

if (response?.promptFeedback?.blockReason === "SAFETY") {
  // Warning for SAFETY errors
  logger.warn(error, response);
} else {
  // Error for all others
  logger.error(error);
}

davidstackio avatar Jan 19 '24 02:01 davidstackio

Related, it doesn't appear that I can import GoogleGenerativeAIError so that I can do e instanceof GoogleGenerativeAIError. Also, guidance on how to differentiate errors would be nice. Currently I don't see a way to get the HTTP status code without parsing the message (e.g. [500 Internal Server Error], [503 Service Unavailable]).

erik-wayhaven avatar Feb 28 '24 19:02 erik-wayhaven

Let's focus this issue on documentation improvements on how to deal with different errors from the model.

We'll use this issue for improvements to how the SDK handles errors: https://github.com/google-gemini/generative-ai-js/issues/82 as it's already got some detailed feedback.

I'll update the title here.

hsubox76 avatar Apr 23 '24 23:04 hsubox76