o
    Th                     @   s   d Z ddlmZmZmZmZ ddlZddlZer"ddlm	Z	 ddl
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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
dZdedefddZdedefddZdedefddZdeeef fddZededejf ddfddZededejd	f ddfddZ  ZS )APIErrorz'General errors raised by the GenAI API.coder   responseNstatusmessageresponse_jsonzaiohttp.ClientResponsec                    s^   || _ || _| || _| || _|r|n| || _t 	| j d| j d| j  d S )N z. )
r
   details_get_messager   _get_statusr   	_get_coder	   super__init__)selfr	   r   r
   	__class__ V/home/air/segue/gemini/backup/venv/lib/python3.10/site-packages/google/genai/errors.pyr   $   s   &zAPIError.__init__returnc                 C      | d| di  dd S )Nr   errorgetr   r   r   r   r   r   4      zAPIError._get_statusc                 C   r   )Nr   r   r   r   r   r   r   r   9   r    zAPIError._get_messagec                 C   r   )Nr	   r   r   r   r   r   r   r   >   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_recordC   s   zAPIError._to_replay_recordc                 C   s   |j dkrdS t|tjr,z
|  | }W n tjjy+   |j}||j	d}Y n
w |j
d di }|j }d|  krBdk rJn nt|||d|  krTdk r\n nt|||| |||)	PRaises an error with detailed error message if the response has an error status.   Nr   r   r   r       X  )status_code
isinstancehttpxResponsereadjsondecoderJSONDecodeErrortextreason_phrasebody_segmentsr   ClientErrorServerError)clsr
   r   r   r)   r   r   r   raise_for_responseQ   s&   

zAPIError.raise_for_responsec                    sp  d}d}t |tjr8|jdkrdS z| I dH  | }W n tjjy3   |j}||j	d}Y nw |j}nVzCddl
}t ||jrq|jdkrKW dS z	| I dH }W n |jjyl   | I dH }||jd}Y nw |j}n	|jd di }W n ty   |jd di }Y nw d|  krdk rn nt|||d|  krdk rn nt|||| |||)	r#   r   Nr$   r%   r   r&   r'   r(   )r*   r+   r,   r)   areadr.   r/   r0   r1   r2   aiohttpClientResponser   client_exceptionsContentTypeErrorreasonr3   r   ImportErrorr4   r5   )r6   r
   r)   r   r   r9   r   r   r   raise_for_async_responsen   sP   



z!APIError.raise_for_async_response)N)__name__
__module____qualname____doc__int__annotations__r   r+   r,   r   r   strr   r   r   r   r   r   dictr"   classmethodr7   r?   __classcell__r   r   r   r   r      sD   
 
r   c                   @      e Zd ZdZdS )r4   z%Client error raised by the GenAI API.Nr@   rA   rB   rC   r   r   r   r   r4          r4   c                   @   rJ   )r5   z%Server error raised by the GenAI API.NrK   r   r   r   r   r5      rL   r5   c                   @   rJ   ) UnknownFunctionCallArgumentErrorzWRaised when the function call argument cannot be converted to the parameter annotation.NrK   r   r   r   r   rM          rM   c                   @   rJ   )UnsupportedFunctionErrorz*Raised when the function is not supported.NrK   r   r   r   r   rO          rO   c                   @   rJ   )FunctionInvocationErrorzDRaised when the function cannot be invoked with the given arguments.NrK   r   r   r   r   rQ      rN   rQ   c                   @   rJ   )ExperimentalWarningz"Warning for experimental features.NrK   r   r   r   r   rR      rP   rR   )rC   typingr   r   r   r   r+   r.   replay_api_clientr   r9   	Exceptionr   r4   r5   
ValueErrorrM   rO   rQ   WarningrR   r   r   r   r   <module>   s    