@@ -22,8 +22,8 @@ import com.google.firebase.vertexai.internal.util.toPublic
22
22
import kotlinx.coroutines.TimeoutCancellationException
23
23
24
24
/* * Parent class for any errors that occur from the [FirebaseVertexAI] SDK. */
25
- public sealed class FirebaseVertexAIException ( message : String , cause : Throwable ? = null ) :
26
- RuntimeException (message, cause) {
25
+ public abstract class FirebaseVertexAIException
26
+ internal constructor (message : String , cause : Throwable ? = null ) : RuntimeException (message, cause) {
27
27
28
28
internal companion object {
29
29
@@ -68,29 +68,29 @@ public sealed class FirebaseVertexAIException(message: String, cause: Throwable?
68
68
}
69
69
70
70
/* * Something went wrong while trying to deserialize a response from the server. */
71
- public class SerializationException (message : String , cause : Throwable ? = null ) :
71
+ public class SerializationException
72
+ internal constructor (message: String , cause: Throwable ? = null ) :
72
73
FirebaseVertexAIException (message, cause)
73
74
74
75
/* * The server responded with a non 200 response code. */
75
- public class ServerException (message : String , cause : Throwable ? = null ) :
76
+ public class ServerException internal constructor (message : String , cause : Throwable ? = null ) :
76
77
FirebaseVertexAIException (message, cause)
77
78
78
- /* * The server responded that the API Key is not valid. */
79
- public class InvalidAPIKeyException (message : String , cause : Throwable ? = null ) :
79
+ /* * The provided API Key is not valid. */
80
+ public class InvalidAPIKeyException
81
+ internal constructor (message: String , cause: Throwable ? = null ) :
80
82
FirebaseVertexAIException (message, cause)
81
83
82
84
/* *
83
- * A request was blocked for some reason .
85
+ * A request was blocked.
84
86
*
85
87
* See the [response's][response] `promptFeedback.blockReason` for more information.
86
88
*
87
- * @property response the full server response for the request .
89
+ * @property response The full server response.
88
90
*/
89
91
// TODO(rlazo): Add secondary constructor to pass through the message?
90
- public class PromptBlockedException (
91
- public val response : GenerateContentResponse ,
92
- cause : Throwable ? = null
93
- ) :
92
+ public class PromptBlockedException
93
+ internal constructor (public val response: GenerateContentResponse , cause: Throwable ? = null ) :
94
94
FirebaseVertexAIException (
95
95
" Prompt was blocked: ${response.promptFeedback?.blockReason?.name} " ,
96
96
cause,
@@ -104,26 +104,24 @@ public class PromptBlockedException(
104
104
* (countries and territories) where the API is available.
105
105
*/
106
106
// TODO(rlazo): Add secondary constructor to pass through the message?
107
- public class UnsupportedUserLocationException (cause : Throwable ? = null ) :
107
+ public class UnsupportedUserLocationException internal constructor (cause : Throwable ? = null ) :
108
108
FirebaseVertexAIException (" User location is not supported for the API use." , cause)
109
109
110
110
/* *
111
111
* Some form of state occurred that shouldn't have.
112
112
*
113
113
* Usually indicative of consumer error.
114
114
*/
115
- public class InvalidStateException (message : String , cause : Throwable ? = null ) :
115
+ public class InvalidStateException internal constructor (message : String , cause : Throwable ? = null ) :
116
116
FirebaseVertexAIException (message, cause)
117
117
118
118
/* *
119
119
* A request was stopped during generation for some reason.
120
120
*
121
- * @property response the full server response for the request
121
+ * @property response The full server response.
122
122
*/
123
- public class ResponseStoppedException (
124
- public val response : GenerateContentResponse ,
125
- cause : Throwable ? = null
126
- ) :
123
+ public class ResponseStoppedException
124
+ internal constructor (public val response: GenerateContentResponse , cause: Throwable ? = null ) :
127
125
FirebaseVertexAIException (
128
126
" Content generation stopped. Reason: ${response.candidates.first().finishReason?.name} " ,
129
127
cause,
@@ -134,7 +132,8 @@ public class ResponseStoppedException(
134
132
*
135
133
* Usually occurs due to a user specified [timeout][RequestOptions.timeout].
136
134
*/
137
- public class RequestTimeoutException (message : String , cause : Throwable ? = null ) :
135
+ public class RequestTimeoutException
136
+ internal constructor (message: String , cause: Throwable ? = null ) :
138
137
FirebaseVertexAIException (message, cause)
139
138
140
139
/* *
@@ -143,17 +142,19 @@ public class RequestTimeoutException(message: String, cause: Throwable? = null)
143
142
* For a list of valid locations, see
144
143
* [Vertex AI locations.](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions)
145
144
*/
146
- public class InvalidLocationException (location : String , cause : Throwable ? = null ) :
145
+ public class InvalidLocationException
146
+ internal constructor (location: String , cause: Throwable ? = null ) :
147
147
FirebaseVertexAIException (" Invalid location \" ${location} \" " , cause)
148
148
149
149
/* *
150
150
* The service is not enabled for this Firebase project. Learn how to enable the required services
151
151
* in the
152
152
* [Firebase documentation.](https://firebase.google.com/docs/vertex-ai/faq-and-troubleshooting#required-apis)
153
153
*/
154
- public class ServiceDisabledException (message : String , cause : Throwable ? = null ) :
154
+ public class ServiceDisabledException
155
+ internal constructor (message: String , cause: Throwable ? = null ) :
155
156
FirebaseVertexAIException (message, cause)
156
157
157
158
/* * Catch all case for exceptions not explicitly expected. */
158
- public class UnknownException (message : String , cause : Throwable ? = null ) :
159
+ public class UnknownException internal constructor (message : String , cause : Throwable ? = null ) :
159
160
FirebaseVertexAIException (message, cause)
0 commit comments