Skip to content

Commit 1ebb8db

Browse files
committed
Add NotConfiguredException with a better error message than provided by the server
1 parent 316e168 commit 1ebb8db

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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 NotConfiguredException(message)
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 NotConfiguredException(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
*

0 commit comments

Comments
 (0)