@@ -357,49 +357,6 @@ def _get_tool_config(
357357 else :
358358 return None
359359
360- def _handle_google_error (self , error : Exception ) -> ModelHTTPError :
361- """Helper method to convert Google API errors to ModelHTTPError."""
362- if isinstance (error , errors .APIError ):
363- return ModelHTTPError (
364- status_code = getattr (error , 'code' , 500 ),
365- model_name = self ._model_name ,
366- body = error .details ,
367- )
368-
369- error_mappings = {
370- errors .UnknownFunctionCallArgumentError : (
371- 400 ,
372- 'the function call argument cannot be converted to the parameter annotation.' ,
373- 'BAD_REQUEST' ,
374- ),
375- errors .UnsupportedFunctionError : (404 , 'the function is not supported.' , 'NOT_FOUND' ),
376- errors .FunctionInvocationError : (
377- 400 ,
378- 'the function cannot be invoked with the given arguments.' ,
379- 'BAD_REQUEST' ,
380- ),
381- errors .UnknownApiResponseError : (
382- 422 ,
383- 'the response from the API cannot be parsed as JSON.' ,
384- 'UNPROCESSABLE_CONTENT' ,
385- ),
386- }
387-
388- if error .__class__ in error_mappings :
389- code , message , status = error_mappings [error .__class__ ]
390- return ModelHTTPError (
391- status_code = code ,
392- model_name = self ._model_name ,
393- body = {'error' : {'code' : code , 'message' : message , 'status' : status }},
394- )
395-
396- # Handle unknown errors as 500 Internal Server Error
397- return ModelHTTPError (
398- status_code = 500 ,
399- model_name = self ._model_name ,
400- body = {'error' : {'code' : 500 , 'message' : str (error ), 'status' : 'INTERNAL_ERROR' }},
401- )
402-
403360 @overload
404361 async def _generate_content (
405362 self ,
@@ -429,14 +386,10 @@ async def _generate_content(
429386 func = self .client .aio .models .generate_content_stream if stream else self .client .aio .models .generate_content
430387 try :
431388 return await func (model = self ._model_name , contents = contents , config = config ) # type: ignore
432- except (
433- errors .APIError ,
434- errors .UnknownFunctionCallArgumentError ,
435- errors .UnsupportedFunctionError ,
436- errors .FunctionInvocationError ,
437- errors .UnknownApiResponseError ,
438- ) as e :
439- raise self ._handle_google_error (e ) from e
389+ except errors .APIError as e :
390+ if (status_code := e .code ) >= 400 :
391+ raise ModelHTTPError (status_code = status_code , model_name = self ._model_name , body = e .details ) from e
392+ raise # pragma: lax no cover
440393
441394 async def _build_content_and_config (
442395 self ,
0 commit comments