Skip to content

Add NotConfiguredException with a better error message than provided by the server. #7233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ private suspend fun validateResponse(response: HttpResponse) {
if (message.contains("The prompt could not be submitted")) {
throw PromptBlockedException(message)
}
if (message.contains("genai config not found")) {
throw NotConfiguredException()
}
getServiceDisabledErrorDetailsOrNull(error)?.let {
val errorMessage =
if (it.metadata?.get("service") == "firebasevertexai.googleapis.com") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ internal constructor(
internal class UnsupportedUserLocationException(cause: Throwable? = null) :
FirebaseCommonAIException("User location is not supported for the API use.", cause)

/**
* The user's project does not have the Gemini Developer API enabled in the Firebase Console.
*
* See the Firebase documentation for the
* [steps](https://firebase.google.com/docs/ai-logic/faq-and-troubleshooting?api=dev#error-genai-config-not-found)
* to enable the Gemini Developer API.
*/
internal class NotConfiguredException(cause: Throwable? = null) :
FirebaseCommonAIException("Gemini Developer API not enabled in Firebase console.", cause)

/**
* Some form of state occurred that shouldn't have.
*
Expand Down