15
15
* limitations under the License.
16
16
*/
17
17
18
- import { RequestOptions , VertexAIErrorCode } from '../types' ;
18
+ import { ErrorDetails , RequestOptions , VertexAIErrorCode } from '../types' ;
19
19
import { VertexAIError } from '../errors' ;
20
20
import { ApiSettings } from '../types/internal' ;
21
21
import {
@@ -151,6 +151,34 @@ export async function makeRequest(
151
151
} catch ( e ) {
152
152
// ignored
153
153
}
154
+ if (
155
+ response . status === 403 &&
156
+ errorDetails . some (
157
+ ( detail : ErrorDetails ) => detail . reason === 'SERVICE_DISABLED'
158
+ ) &&
159
+ errorDetails . some ( ( detail : ErrorDetails ) =>
160
+ (
161
+ detail . links as Array < Record < string , string > >
162
+ ) ?. [ 0 ] ?. description . includes (
163
+ 'Google developers console API activation'
164
+ )
165
+ )
166
+ ) {
167
+ throw new VertexAIError (
168
+ VertexAIErrorCode . API_NOT_ENABLED ,
169
+ `The Vertex AI for Firebase SDK requires the Firebase Vertex AI API ` +
170
+ `firebasevertexai.googleapis.com to be enabled for your ` +
171
+ `project. Get started in the Firebase Console` +
172
+ ` (https://console.firebase.google.com/project/${ url . apiSettings . project } /genai/vertex)` +
173
+ ` or verify that the API is enabled in the Google Cloud` +
174
+ ` Console (https://console.developers.google.com/apis/api/firebasevertexai.googleapis.com/overview?project=${ url . apiSettings . project } ).` ,
175
+ {
176
+ status : response . status ,
177
+ statusText : response . statusText ,
178
+ errorDetails
179
+ }
180
+ ) ;
181
+ }
154
182
throw new VertexAIError (
155
183
VertexAIErrorCode . FETCH_ERROR ,
156
184
`Error fetching from ${ url } : [${ response . status } ${ response . statusText } ] ${ message } ` ,
@@ -165,6 +193,7 @@ export async function makeRequest(
165
193
let err = e as Error ;
166
194
if (
167
195
( e as VertexAIError ) . code !== VertexAIErrorCode . FETCH_ERROR &&
196
+ ( e as VertexAIError ) . code !== VertexAIErrorCode . API_NOT_ENABLED &&
168
197
e instanceof Error
169
198
) {
170
199
err = new VertexAIError (
0 commit comments