
    h                     D    d dl mZ d dlmZmZmZ d dlmZ  G d d      Zy)    )Union)DB_CONNECTION_ERROR_TYPESProxyErrorTypesProxyException)str_to_boolc                   V    e Zd ZdZedefd       Zededefd       Zedefd       Z	y)PrismaDBExceptionHandlerz<
    Class to handle DB Exceptions or Connection Errors
    returnc                  t    ddl m}  | j                  dd      }t        |t              r|S t        |      du ryy)zj
        Returns True if the request should be allowed to proceed despite the DB connection error
        r   )general_settings allow_requests_on_db_unavailableFT)litellm.proxy.proxy_serverr   get
isinstanceboolr   )r   !_allow_requests_on_db_unavailables     ^/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/proxy/db/exception_handler.py&should_allow_request_on_db_unavailablez?PrismaDBExceptionHandler.should_allow_request_on_db_unavailable   sE    
 	@>N>R>R.?
) 7>4489TA    ec                     ddl }t        | t              ryt        | |j                  j                        ryt        | t
              r| j                  t        j                  k(  ryy)z\
        Returns True if the exception is from a database outage / connection error
        r   NTF)	prismar   r   errorsPrismaErrorr   typer   no_db_connection)r   r   s     r   is_database_connection_errorz5PrismaDBExceptionHandler.is_database_connection_error    sM    
 	a23a223a(QVV7W7W-Wr   c                 Z    t         j                  |       rt         j                         ry| )aK  
        Primary handler for `allow_requests_on_db_unavailable` flag. Decides whether to raise a DB Exception or not based on the flag.

        - If exception is a DB Connection Error, and `allow_requests_on_db_unavailable` is True,
            - Do not raise an exception, return None
        - Else, raise the exception
        N)r	   r   r   )r   s    r   handle_db_exceptionz,PrismaDBExceptionHandler.handle_db_exception/   s&     %AA!D(OOQr   N)
__name__
__module____qualname____doc__staticmethodr   r   	Exceptionr   r    r   r   r	   r	      s_     D   	 d   y  r   r	   N)	typingr   litellm.proxy._typesr   r   r   litellm.secret_managers.mainr   r	   r&   r   r   <module>r*      s!     
 52 2r   