Skip to content

Commit 38806af

Browse files
committed
Rename exception
1 parent c16d020 commit 38806af

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ internal constructor(
131131
.body<GenerateContentResponse>()
132132
.validate()
133133
} catch (e: Throwable) {
134-
throw GoogleGenerativeAIException.from(e)
134+
throw FirebaseCommonAIException.from(e)
135135
}
136136

137137
fun generateContentStream(request: GenerateContentRequest): Flow<GenerateContentResponse> =
@@ -142,7 +142,7 @@ internal constructor(
142142
applyCommonConfiguration(request)
143143
}
144144
.map { it.validate() }
145-
.catch { throw GoogleGenerativeAIException.from(it) }
145+
.catch { throw FirebaseCommonAIException.from(it) }
146146

147147
suspend fun countTokens(request: CountTokensRequest): CountTokensResponse =
148148
try {
@@ -154,7 +154,7 @@ internal constructor(
154154
.also { validateResponse(it) }
155155
.body()
156156
} catch (e: Throwable) {
157-
throw GoogleGenerativeAIException.from(e)
157+
throw FirebaseCommonAIException.from(e)
158158
}
159159

160160
private fun HttpRequestBuilder.applyCommonConfiguration(request: Request) {

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ import io.ktor.serialization.JsonConvertException
2020
import kotlinx.coroutines.TimeoutCancellationException
2121

2222
/** Parent class for any errors that occur. */
23-
internal sealed class GoogleGenerativeAIException(message: String, cause: Throwable? = null) :
23+
internal sealed class FirebaseCommonAIException(message: String, cause: Throwable? = null) :
2424
RuntimeException(message, cause) {
2525
companion object {
2626

2727
/**
28-
* Converts a [Throwable] to a [GoogleGenerativeAIException].
28+
* Converts a [Throwable] to a [FirebaseCommonAIException].
2929
*
3030
* Will populate default messages as expected, and propagate the provided [cause] through the
3131
* resulting exception.
3232
*/
33-
fun from(cause: Throwable): GoogleGenerativeAIException =
33+
fun from(cause: Throwable): FirebaseCommonAIException =
3434
when (cause) {
35-
is GoogleGenerativeAIException -> cause
35+
is FirebaseCommonAIException -> cause
3636
is JsonConvertException,
3737
is kotlinx.serialization.SerializationException ->
3838
SerializationException(
@@ -48,15 +48,15 @@ internal sealed class GoogleGenerativeAIException(message: String, cause: Throwa
4848

4949
/** Something went wrong while trying to deserialize a response from the server. */
5050
internal class SerializationException(message: String, cause: Throwable? = null) :
51-
GoogleGenerativeAIException(message, cause)
51+
FirebaseCommonAIException(message, cause)
5252

5353
/** The server responded with a non 200 response code. */
5454
internal class ServerException(message: String, cause: Throwable? = null) :
55-
GoogleGenerativeAIException(message, cause)
55+
FirebaseCommonAIException(message, cause)
5656

5757
/** The server responded that the API Key is no valid. */
5858
internal class InvalidAPIKeyException(message: String, cause: Throwable? = null) :
59-
GoogleGenerativeAIException(message, cause)
59+
FirebaseCommonAIException(message, cause)
6060

6161
/**
6262
* A request was blocked for some reason.
@@ -69,7 +69,7 @@ internal class PromptBlockedException(
6969
val response: GenerateContentResponse,
7070
cause: Throwable? = null
7171
) :
72-
GoogleGenerativeAIException(
72+
FirebaseCommonAIException(
7373
"Prompt was blocked: ${response.promptFeedback?.blockReason?.name}",
7474
cause,
7575
)
@@ -82,15 +82,15 @@ internal class PromptBlockedException(
8282
* territories) where the API is available.
8383
*/
8484
internal class UnsupportedUserLocationException(cause: Throwable? = null) :
85-
GoogleGenerativeAIException("User location is not supported for the API use.", cause)
85+
FirebaseCommonAIException("User location is not supported for the API use.", cause)
8686

8787
/**
8888
* Some form of state occurred that shouldn't have.
8989
*
9090
* Usually indicative of consumer error.
9191
*/
9292
internal class InvalidStateException(message: String, cause: Throwable? = null) :
93-
GoogleGenerativeAIException(message, cause)
93+
FirebaseCommonAIException(message, cause)
9494

9595
/**
9696
* A request was stopped during generation for some reason.
@@ -101,7 +101,7 @@ internal class ResponseStoppedException(
101101
val response: GenerateContentResponse,
102102
cause: Throwable? = null
103103
) :
104-
GoogleGenerativeAIException(
104+
FirebaseCommonAIException(
105105
"Content generation stopped. Reason: ${response.candidates?.first()?.finishReason?.name}",
106106
cause,
107107
)
@@ -112,16 +112,16 @@ internal class ResponseStoppedException(
112112
* Usually occurs due to a user specified [timeout][RequestOptions.timeout].
113113
*/
114114
internal class RequestTimeoutException(message: String, cause: Throwable? = null) :
115-
GoogleGenerativeAIException(message, cause)
115+
FirebaseCommonAIException(message, cause)
116116

117117
/** The quota for this API key is depleted, retry this request at a later time. */
118118
internal class QuotaExceededException(message: String, cause: Throwable? = null) :
119-
GoogleGenerativeAIException(message, cause)
119+
FirebaseCommonAIException(message, cause)
120120

121121
/** The service is not enabled for this project. Visit the Firebase Console to enable it. */
122122
internal class ServiceDisabledException(message: String, cause: Throwable? = null) :
123-
GoogleGenerativeAIException(message, cause)
123+
FirebaseCommonAIException(message, cause)
124124

125125
/** Catch all case for exceptions not explicitly expected. */
126126
internal class UnknownException(message: String, cause: Throwable? = null) :
127-
GoogleGenerativeAIException(message, cause)
127+
FirebaseCommonAIException(message, cause)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.google.firebase.vertexai.type
1818

1919
import com.google.firebase.vertexai.FirebaseVertexAI
20-
import com.google.firebase.vertexai.common.GoogleGenerativeAIException
20+
import com.google.firebase.vertexai.common.FirebaseCommonAIException
2121
import com.google.firebase.vertexai.internal.util.toPublic
2222
import kotlinx.coroutines.TimeoutCancellationException
2323

@@ -36,7 +36,7 @@ sealed class FirebaseVertexAIException(message: String, cause: Throwable? = null
3636
fun from(cause: Throwable): FirebaseVertexAIException =
3737
when (cause) {
3838
is FirebaseVertexAIException -> cause
39-
is GoogleGenerativeAIException ->
39+
is FirebaseCommonAIException ->
4040
when (cause) {
4141
is com.google.firebase.vertexai.common.SerializationException ->
4242
SerializationException(cause.message ?: "", cause.cause)

0 commit comments

Comments
 (0)