diff --git a/firebase-ai/CHANGELOG.md b/firebase-ai/CHANGELOG.md index 7f86ca48d2b..2ca8ddcc1a6 100644 --- a/firebase-ai/CHANGELOG.md +++ b/firebase-ai/CHANGELOG.md @@ -1,4 +1,6 @@ # Unreleased +* [changed] Added better description for requests which fail due to the Gemini API not being + configured. * [feature] added support for Imagen Editing, including inpainting, outpainting, control, style transfer, and subject references (#7075) diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/APIController.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/APIController.kt index f1f51dabab9..60912fbf1a4 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/APIController.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/APIController.kt @@ -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") { diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/Exceptions.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/Exceptions.kt index 6e2ff67ca4d..bd9ee4ce9c9 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/Exceptions.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/common/Exceptions.kt @@ -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. * diff --git a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Exceptions.kt b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Exceptions.kt index 57a27f241a0..1355c2dc7ce 100644 --- a/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Exceptions.kt +++ b/firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Exceptions.kt @@ -61,6 +61,8 @@ internal constructor(message: String, cause: Throwable? = null) : RuntimeExcepti ContentBlockedException(cause.message ?: "", cause.cause) is com.google.firebase.ai.common.QuotaExceededException -> QuotaExceededException(cause.message ?: "", cause.cause) + is com.google.firebase.ai.common.NotConfiguredException -> + NotConfiguredException(cause.cause) else -> UnknownException(cause.message ?: "", cause) } is TimeoutCancellationException -> @@ -149,6 +151,16 @@ internal constructor(message: String, cause: Throwable? = null) : public class UnsupportedUserLocationException internal constructor(cause: Throwable? = null) : FirebaseAIException("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 internal constructor(cause: Throwable? = null) : + FirebaseAIException("Gemini Developer API not enabled in Firebase console.", cause) + /** * Some form of state occurred that shouldn't have. *