o
    Zh"                     @   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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  ZS )APIErrorz'General errors raised by the GenAI API.coder   responseNstatusmessagec                    s   || _ d }t|tjr7z| }W n. tjjy%   |j}||jd}Y n tj	y6   d}||jd}Y n
w |j
d di }|| _| || _| || _|rS|n| || _t | j d| j d| j  d S )N)r   r   zResponse not readr   error z. )r
   
isinstancehttpxResponsejsondecoderJSONDecodeErrortextZreason_phraseZResponseNotReadZbody_segmentsgetdetails_get_messager   _get_statusr   	_get_coder	   super__init__)selfr	   r
   r   response_json	__class__ J/var/www/html/lang_env/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   C      zAPIError._get_statusc                 C   r#   )Nr   r   r$   r%   r!   r!   r"   r   H   r&   zAPIError._get_messagec                 C   r#   )Nr	   r   r$   r%   r!   r!   r"   r   M   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_recordR   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_response`   s   



zAPIError.raise_for_response)__name__
__module____qualname____doc__int__annotations__r   r   r   r   r   strr   r   r   r   r   r(   classmethodr.   __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r/   r0   r1   r2   r!   r!   r!   r"   r+   q       r+   c                   @   r8   )r,   z%Server error raised by the GenAI API.Nr9   r!   r!   r!   r"   r,   v   r:   r,   c                   @   r8   ) UnknownFunctionCallArgumentErrorzWRaised when the function call argument cannot be converted to the parameter annotation.Nr9   r!   r!   r!   r"   r;   {       r;   c                   @   r8   )UnsupportedFunctionErrorz*Raised when the function is not supported.Nr9   r!   r!   r!   r"   r=          r=   c                   @   r8   )FunctionInvocationErrorzDRaised when the function cannot be invoked with the given arguments.Nr9   r!   r!   r!   r"   r?      r<   r?   c                   @   r8   )ExperimentalWarningz"Warning for experimental features.Nr9   r!   r!   r!   r"   r@      r>   r@   )r2   typingr   r   r   r   r   r   Zreplay_api_clientr   	Exceptionr   r+   r,   
ValueErrorr;   r=   r?   Warningr@   r!   r!   r!   r"   <module>   s   V