
    Lh                        d Z ddlmZmZmZmZ ddlZddlZddlm	Z	 er
ddl
mZ ddlZ G d de      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Ze	j,                  Zy)z Error classes for the GenAI SDK.    )AnyOptionalTYPE_CHECKINGUnionN   )_common)ReplayResponsec                   x    e Zd ZU dZeed<   edej                  f   ed<   dZ	e
e   ed<   dZe
e   ed<   	 ddedede
edej                  d	f      f fd
ZdedefdZdedefdZdedefdZdej&                  fdZededej                  f   ddfd       Zededej                  d	f   ddfd       Z xZS )APIErrorz'General errors raised by the GenAI API.coder	   responseNstatusmessageresponse_jsonzaiohttp.ClientResponsec                 ^   t        |t              rt        |      dk(  r|d   }|| _        || _        | j                  |      | _        | j                  |      | _        |r|n| j                  |      | _
        t        | 1  | j                   d| j                   d| j                          y )Nr   r    z. )
isinstancelistlenr   details_get_messager   _get_statusr   	_get_coder   super__init__)selfr   r   r   	__class__s       F/var/www/html/venv/lib/python3.12/site-packages/google/genai/errors.pyr   zAPIError.__init__%   s     -&3}+=+B#A&mDM DL$$]3DL""=1DK$.."?DI	G		{!DKK=4<<.AB    returnc                 f    |j                  d|j                  di       j                  dd             S )Nr   errorgetr   r   s     r   r   zAPIError._get_status8   s4    -##GR044XtD r   c                 f    |j                  d|j                  di       j                  dd             S )Nr   r"   r#   r%   s     r   r   zAPIError._get_message=   s4    =$$Wb155iF r   c                 f    |j                  d|j                  di       j                  dd             S )Nr   r"   r#   r%   s     r   r   zAPIError._get_codeB   s4    !!'2.2264@ r   c                 N    d| j                   | j                  | j                  diS )zReturns a dictionary representation of the error for replay recording.

    details is not included since it may expose internal information in the
    replay file.
    r"   r   r   r   r)   )r   s    r   _to_replay_recordzAPIError._to_replay_recordG   s+     	II||kk
 r   c                    |j                   dk(  ryt        |t        j                        r"	 |j	                          |j                         }n|j                  d   j                  di       }|j                   }d|cxk  rdk  rn nt        |||      d|cxk  rdk  rn nt        |||       | |||      # t
        j                  j                  $ r |j                  }||j                  d}Y w xY w)	PRaises an error with detailed error message if the response has an error status.   Nr   r   r   r"       X  )status_coder   httpxResponsereadjsondecoderJSONDecodeErrortextreason_phrasebody_segmentsr$   ClientErrorServerError)clsr   r   r   r2   s        r   raise_for_responsezAPIError.raise_for_responseU   s    
 s"(ENN+
  ,,Q/33GR@m&&K
kC]H==		!c	!]H==]H55 \\)) 
--,,

s    B8 88C32C3c                 *  K   d}d}t        |t        j                        rF|j                  dk(  ry	 |j	                          d{    |j                         }|j                  }nt        |d      rHt        |d      r<|j                  dk(  ry|j                  d   j                  di       }|j                  }ni	 ddl}t        ||j                        r6|j                  dk(  ry	 |j                          d{   }|j                  }nt'        dt)        |             	 d	|cxk  rd
k  rn nt-        |||      d
|cxk  rdk  rn nt/        |||       | |||      7 # t
        j                  j                  $ r |j                  }||j                  d}Y Hw xY w7 # |j                   j"                  $ r+ |j                          d{  7  }||j$                  d}Y w xY w# t*        $ r t'        dt)        |             w xY ww)r,   r   Nr-   r.   r;   r2   r"   zUnsupported response type: r/   r0   r1   )r   r3   r4   r2   areadr6   r7   r8   r9   r:   hasattrr;   r$   aiohttpClientResponser   client_exceptionsContentTypeErrorreason
ValueErrortypeImportErrorr<   r=   )r>   r   r2   r   r   rC   s         r   raise_for_async_responsez!APIError.raise_for_async_responser   s     KM(ENN+				$
nn  ((k	?	+-1 
			$,,Q/33GR@m((kIh 6 67__#"*--/1M !+8h8HIJ
J  kC]H==		!c	!]H==]H55U 	\\)) 
--,,

, 2**;; $MMO++G""//M  I6tH~6FGHHIs   /HE' E$E' A!H<)G/ %H'F( :F&;F( ?$G/ #AH$E' '8F#H"F##H&F( (,G,GG,)G/ +G,,G/ /!HH)N)__name__
__module____qualname____doc__int__annotations__r   r3   r4   r   r   strr   r   r   r   r   r   r   
StringDictr*   classmethodr?   rK   __classcell__)r   s   @r   r   r      s8   /)"ENN233&(3-'8C= CC C 
 %..2JJ
K	C&s s 
  
S S 
!3!3  6+U^^;<66 68 76
ENN,D
D76
 76 76r   r   c                       e Zd ZdZy)r<   z%Client error raised by the GenAI API.NrL   rM   rN   rO    r   r   r<   r<          -r   r<   c                       e Zd ZdZy)r=   z%Server error raised by the GenAI API.NrW   rX   r   r   r=   r=      rY   r   r=   c                       e Zd ZdZy) UnknownFunctionCallArgumentErrorzWRaised when the function call argument cannot be converted to the parameter annotation.NrW   rX   r   r   r\   r\      s    _r   r\   c                       e Zd ZdZy)UnsupportedFunctionErrorz*Raised when the function is not supported.NrW   rX   r   r   r^   r^      s    2r   r^   c                       e Zd ZdZy)FunctionInvocationErrorzDRaised when the function cannot be invoked with the given arguments.NrW   rX   r   r   r`   r`      s    Lr   r`   c                       e Zd ZdZy)UnknownApiResponseErrorz?Raised when the response from the API cannot be parsed as JSON.NrW   rX   r   r   rb   rb      s    Gr   rb   )rO   typingr   r   r   r   r3   r6    r   replay_api_clientr	   rC   	Exceptionr   r<   r=   rH   r\   r^   r`   rb   ExperimentalWarningrX   r   r   <module>rh      s     ' 6 6    /M6y M6`( 
( 
z 
z 
j 
j  11 r   