o
    0Xxi                     @   s   d Z ddlmZmZmZmZ ddlZerddlmZ G dd de	Z
G dd	 d	e
ZG d
d de
ZG dd deZG dd deZG dd deZG dd deZdS )z Error classes for the GenAI SDK.    )AnyOptionalTYPE_CHECKINGUnionN   )ReplayResponsec                       s   e Zd ZU dZeed< ejed< dZe	e
 ed< dZe	e
 ed< dZe	e ed< dedeejdf f fdd	Zd
d Zdd Zdd Zdd Zedeejdf fddZ  ZS )APIErrorz'General errors raised by the GenAI API.coderesponseNstatusmessager   c                    s   || _ t|tjr"z| }W n tjjy!   |j|jd}Y n
w |j	d 
di }|| _| || _| || _|r>|n| || _t | j d| j d| j  d S )N)r   r   r   error z. )r
   
isinstancerequestsResponsejson
exceptionsJSONDecodeErrortextreasonbody_segmentsgetdetails_get_messager   _get_statusr   	_get_coder	   super__init__)selfr	   r
   response_json	__class__ R/home/air/biblejyuku/back/venv/lib/python3.10/site-packages/google/genai/errors.pyr   $   s   
&zAPIError.__init__c                 C      | d| di  dd S )Nr   r   r   r   r    r#   r#   r$   r   =      zAPIError._get_statusc                 C   r%   )Nr   r   r&   r'   r#   r#   r$   r   B   r(   zAPIError._get_messagec                 C   r%   )Nr	   r   r&   r'   r#   r#   r$   r   G   r(   zAPIError._get_codec                 C   s   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   r#   r#   r$   _to_replay_recordL   s   zAPIError._to_replay_recordc                 C   sb   |j dkrdS |j }d|  krdk rn nt||d|  kr%dk r,n nt||| ||)zPRaises an error with detailed error message if the response has an error status.   Ni  i  iX  )status_codeClientErrorServerError)clsr
   r,   r#   r#   r$   raise_for_responseZ   s   



zAPIError.raise_for_response)__name__
__module____qualname____doc__int__annotations__r   r   r   r   strr   r
   r   r   r   r   r   r   r*   classmethodr0   __classcell__r#   r#   r!   r$   r      s(   
 
r   c                   @      e Zd ZdZdS )r-   z%Client error raised by the GenAI API.Nr1   r2   r3   r4   r#   r#   r#   r$   r-   k       r-   c                   @   r:   )r.   z%Server error raised by the GenAI API.Nr;   r#   r#   r#   r$   r.   p   r<   r.   c                   @   r:   ) UnknownFunctionCallArgumentErrorzWRaised when the function call argument cannot be converted to the parameter annotation.Nr;   r#   r#   r#   r$   r=   u       r=   c                   @   r:   )UnsupportedFunctionErrorz*Raised when the function is not supported.Nr;   r#   r#   r#   r$   r?   {       r?   c                   @   r:   )FunctionInvocationErrorzDRaised when the function cannot be invoked with the given arguments.Nr;   r#   r#   r#   r$   rA      r>   rA   c                   @   r:   )ExperimentalWarningz"Warning for experimental features.Nr;   r#   r#   r#   r$   rB      r@   rB   )r4   typingr   r   r   r   r   replay_api_clientr   	Exceptionr   r-   r.   
ValueErrorr=   r?   rA   WarningrB   r#   r#   r#   r$   <module>   s   P