Skip to content

Commit 8b1b50d

Browse files
authored
Add NotConfiguredException with a better error message than provided by the server. (#7233)
The previous error text "genai config not found" is ambiguous and as a generic ServerException did not provide documentation for resolutions.
1 parent 16d2999 commit 8b1b50d

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

firebase-ai/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Unreleased
2+
* [changed] Added better description for requests which fail due to the Gemini API not being
3+
configured.
24
* [feature] added support for Imagen Editing, including inpainting, outpainting, control, style
35
transfer, and subject references (#7075)
46

firebase-ai/src/main/kotlin/com/google/firebase/ai/common/APIController.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ private suspend fun validateResponse(response: HttpResponse) {
334334
if (message.contains("The prompt could not be submitted")) {
335335
throw PromptBlockedException(message)
336336
}
337+
if (message.contains("genai config not found")) {
338+
throw APINotConfiguredException()
339+
}
337340
getServiceDisabledErrorDetailsOrNull(error)?.let {
338341
val errorMessage =
339342
if (it.metadata?.get("service") == "firebasevertexai.googleapis.com") {

firebase-ai/src/main/kotlin/com/google/firebase/ai/common/Exceptions.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ internal constructor(
8989
internal class UnsupportedUserLocationException(cause: Throwable? = null) :
9090
FirebaseCommonAIException("User location is not supported for the API use.", cause)
9191

92+
/**
93+
* The user's project does not have the Gemini Developer API enabled in the Firebase Console.
94+
*
95+
* See the Firebase documentation for the
96+
* [steps](https://firebase.google.com/docs/ai-logic/faq-and-troubleshooting?api=dev#error-genai-config-not-found)
97+
* to enable the Gemini Developer API.
98+
*/
99+
internal class APINotConfiguredException(cause: Throwable? = null) :
100+
FirebaseCommonAIException("Gemini Developer API not enabled in Firebase console.", cause)
101+
92102
/**
93103
* Some form of state occurred that shouldn't have.
94104
*

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Exceptions.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ internal constructor(message: String, cause: Throwable? = null) : RuntimeExcepti
6161
ContentBlockedException(cause.message ?: "", cause.cause)
6262
is com.google.firebase.ai.common.QuotaExceededException ->
6363
QuotaExceededException(cause.message ?: "", cause.cause)
64+
is com.google.firebase.ai.common.APINotConfiguredException ->
65+
APINotConfiguredException(cause.cause)
6466
else -> UnknownException(cause.message ?: "", cause)
6567
}
6668
is TimeoutCancellationException ->
@@ -149,6 +151,16 @@ internal constructor(message: String, cause: Throwable? = null) :
149151
public class UnsupportedUserLocationException internal constructor(cause: Throwable? = null) :
150152
FirebaseAIException("User location is not supported for the API use.", cause)
151153

154+
/**
155+
* The user's project does not have the Gemini Developer API enabled in the Firebase Console.
156+
*
157+
* See the Firebase documentation for the
158+
* [steps](https://firebase.google.com/docs/ai-logic/faq-and-troubleshooting?api=dev#error-genai-config-not-found)
159+
* to enable the Gemini Developer API.
160+
*/
161+
internal class APINotConfiguredException internal constructor(cause: Throwable? = null) :
162+
FirebaseAIException("Gemini Developer API not enabled in Firebase console.", cause)
163+
152164
/**
153165
* Some form of state occurred that shouldn't have.
154166
*

0 commit comments

Comments
 (0)