
    [Th                        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       X/home/www/backend.miabetepe.com/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                  }np	 ddl
}t        ||j                        r6|j                  dk(  ry	 |j                          d{   }|j                  }n|j                   d   j#                  di       }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 w xY w7 # |j                  j                  $ r+ |j                          d{  7  }||j                  d}Y w xY w# t$        $ r" |j                   d   j#                  di       }Y w xY ww)	r,   r   Nr-   r.   r"   r/   r0   r1   )r   r3   r4   r2   areadr6   r7   r8   r9   r:   aiohttpClientResponser   client_exceptionsContentTypeErrorreasonr;   r$   ImportErrorr<   r=   )r>   r   r2   r   r   rB   s         r   raise_for_async_responsez!APIError.raise_for_async_responser   s     KM(ENN+				$
nn  ((kCh 6 67__#"*--/1M !+"00377D- kC]H==		!c	!]H==]H55G 	\\)) 
--,,

 2**;; $MMO++G""//M  C ..q155grBCs   /GD DD G()F  GE &E'E +,F  A GD 8EGEGE ,FFFF  FF   (GG
GG)N)__name__
__module____qualname____doc__int__annotations__r   r3   r4   r   r   strr   r   r   r   r   r   r   
StringDictr*   classmethodr?   rH   __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 06
ENN,D
D06
 06 06r   r   c                       e Zd ZdZy)r<   z%Client error raised by the GenAI API.NrI   rJ   rK   rL    r   r   r<   r<          -r   r<   c                       e Zd ZdZy)r=   z%Server error raised by the GenAI API.NrT   rU   r   r   r=   r=      rV   r   r=   c                       e Zd ZdZy) UnknownFunctionCallArgumentErrorzWRaised when the function call argument cannot be converted to the parameter annotation.NrT   rU   r   r   rY   rY      s    _r   rY   c                       e Zd ZdZy)UnsupportedFunctionErrorz*Raised when the function is not supported.NrT   rU   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.NrT   rU   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.NrT   rU   r   r   r_   r_      s    Gr   r_   )rL   typingr   r   r   r   r3   r6    r   replay_api_clientr	   rB   	Exceptionr   r<   r=   
ValueErrorrY   r[   r]   r_   ExperimentalWarningrU   r   r   <module>rf      s     ' 6 6    /F6y F6R( 
( 
z 
z 
j 
j  11 r   