
    	,hr                        d dl Z d dlmZmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ  e
e      Z G d d	e      Z G d
 de      ZdededdfdZdededefdZdededefdZdededefdZdededefdZdededefdZy)    N)HTTPExceptionRequest)JSONResponse)ProgrammingError)OperationalError)
get_logger)CUSTOM_LOGGERc            	       <     e Zd ZdZddedededz  ddf fdZ xZS )	CustomHttpExceptionzFCustom HTTP Exception class to handle exceptions with custom messages.Nstatus_codedetailheadersreturnc                 *    t         |   |||       y N)r   r   r   super__init__selfr   r   r   	__class__s       )/var/www/html/RetailAPI/app/exceptions.pyr   zCustomHttpException.__init__       [Q    )N	__name__
__module____qualname____doc__intstrdictr   __classcell__r   s   @r   r   r      s7    PRC R Rtd{ RVZ R Rr   r   c            	       <     e Zd ZdZddedededz  ddf fdZ xZS )	SessionExceptionzSession expired exception.Nr   r   r   r   c                 *    t         |   |||       y r   r   r   s       r   r   zSessionException.__init__   r   r   )i  zSession expiredNr   r$   s   @r   r&   r&      s:    $RC Rs RY]`dYd Rpt R Rr   r&   requestexcr   c                 @   | j                   j                  }d| d| }t        j                         }| d| }t        j                  |       t        j                  |       t        |t              s+t        j                  |       t        j                  |       yy)zLog the error message.z[Error] z: 
N)urlpath	traceback
format_exclogerrorr	   	error_log
isinstancer   stack_trace)r(   r)   url_patherror_messageerror_tracebackfull_error_messages         r   	log_errorr9      s    {{Hxj3%0M**,O)?"_,=>IImM*c=)		$%!!/2 *r   c                 h    |j                   }t        | |       t        dd|j                  d|      S )z1HTTP Exception handler to return custom messages.   -1)statusmessage)r   contentr   )r   r9   r   r   )r(   r)   r   s      r   http_exception_error_handlerr@   *   s.    kkGgsCDSZZ1Xbijjr   c                    K   t        |      }t        | |       d|v rd|v rt        ddd|d      S t        ddd|d      S w)	z"Handle ProgrammingError exception.Tablezdoesn't existr;   r<   zRequested resource not foundr=   r>   r1   r   r?   zInternal server error)r!   r9   r   r(   r)   r6   s      r   handle_programming_errorrF   2   sa     HMgs-O}$D#0NYfg
 	
 ,Cm\ s   AAc                 V   K   t        | |       t        dddt        |      d      S w)zHandle generic exception.r;   r<   zAn error occurredrC   rD   )r9   r   r!   )r(   r)   s     r    handle_generic_exception_handlerrH   A   s/     gs,?#c(S s   ')c                 R   K   t        |      }t        | |       t        d|      S w)z"Handle OperationalError exception.  r   r   r!   r9   r   rE   s      r    handel_operational_error_handlerrM   J   &     HMgsS??   %'c                 R   K   t        |      }t        | |       t        d|      S w)z Handle AttributeError exception.rJ   rK   rL   rE   s      r   handel_attribute_error_handlerrQ   P   rN   rO   )r.   fastapir   r   fastapi.responsesr   sqlalchemy.excr   r   app.logr   app.utils.log_utilsr	   r   r0   r   r&   	Exceptionr9   r@   rF   rH   rM   AttributeErrorrQ    r   r   <module>rZ      s     * * + +  -R- RR} R
3w 
3Y 
34 
3k' k k, kG :J | G ) P\ @G @BR @Wd @@' @ @S` @r   