o
    %gd                     @   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	 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edededejf f fd	d
Zdd Zdd Zdd Zdd Zededejf fddZededejf fddZ  ZS )APIErrorz'General errors raised by the GenAI API.coder   responseNstatusmessageresponse_jsonc                    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__ U/mnt/skqttb/ctump_chatbot/chatbot/lib/python3.10/site-packages/google/genai/errors.pyr   #   s   &zAPIError.__init__c                 C      | d| di  dd S )Nr   errorgetr   r   r   r   r   r   1      zAPIError._get_statusc                 C   r   )Nr   r   r   r   r   r   r   r   6   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_record@   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|||| |||	zPRaises an error with detailed error message if the response has an error status.   N)r   r   r   r   i  i  iX  )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_responseN   s&   

zAPIError.raise_for_responsec                    s   |j dkrdS t|tjr0z| I dH  | }W n tjjy/   |j}||j	d}Y n
w |j
d di }|j }d|  krFdk rNn nt|||d|  krXdk r`n nt|||| |||r"   )r$   r%   r&   r'   areadr)   r*   r+   r,   r-   r.   r   r/   r0   r1   r   r   r   raise_for_async_responsek   s(   

z!APIError.raise_for_async_response)__name__
__module____qualname____doc__int__annotations__r   r&   r'   r   r   strr   r   r   r   r   r   r!   classmethodr3   r5   __classcell__r   r   r   r   r      s2   
 r   c                   @      e Zd ZdZdS )r/   z%Client error raised by the GenAI API.Nr6   r7   r8   r9   r   r   r   r   r/          r/   c                   @   r?   )r0   z%Server error raised by the GenAI API.Nr@   r   r   r   r   r0      rA   r0   c                   @   r?   ) UnknownFunctionCallArgumentErrorzWRaised when the function call argument cannot be converted to the parameter annotation.Nr@   r   r   r   r   rB          rB   c                   @   r?   )UnsupportedFunctionErrorz*Raised when the function is not supported.Nr@   r   r   r   r   rD          rD   c                   @   r?   )FunctionInvocationErrorzDRaised when the function cannot be invoked with the given arguments.Nr@   r   r   r   r   rF      rC   rF   c                   @   r?   )ExperimentalWarningz"Warning for experimental features.Nr@   r   r   r   r   rG      rE   rG   )r9   typingr   r   r   r   r&   r)   replay_api_clientr   	Exceptionr   r/   r0   
ValueErrorrB   rD   rF   WarningrG   r   r   r   r   <module>   s   m