generative-ai-js
generative-ai-js copied to clipboard
Update documentation to explain possible error codes from the model endpoint
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!.
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);
}
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]).
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.