
    Di                         d Z ddlmZ ddlmZmZmZmZ  G d de      Z G d de      Z	 G d d	e      Z
 G d
 de      Z G d de      Z G d de      Z G d de      Z G d de      Zy)z
Custom API Exception Classes
    )datetime)AnyDictListUnionc                        e Zd ZdZ	 	 	 	 	 ddededeeeef   e	eeef      ef   dz  dedz  dedz  f
 fdZ
d	efd
Zd	efdZ xZS )APIExceptionz
    Custom API exception for structured error handling.
    
    Provides a consistent way to raise and handle application-specific errors
    with detailed context information.
    Nmessagestatus_codeerrormodule
request_idc                     || _         || _        |xs || _        || _        || _        t        j                         j                         dz   | _        t        | )  | j                          y)a7  
        Initialize APIException.
        
        Args:
            message: Human-readable error message
            status_code: HTTP status code
            error: Detailed error information
            module: Module/component where error occurred
            request_id: Unique request identifier
        ZN)r
   r   r   r   r   r   utcnow	isoformat	timestampsuper__init__)selfr
   r   r   r   r   	__class__s         Q/var/www/html/hwPaymentPortal-be-dev/hw-payment-portal-api/src/core/exceptions.pyr   zAPIException.__init__   s[    $ &%g
$!*446<&    returnc                 :    | j                    d| j                   dS )z&String representation of the exceptionz
 (Status: )r
   r   r   s    r   __str__zAPIException.__str__+   s     ,,z$*:*:);1==r   c           	      p    d| j                    d| j                   d| j                   d| j                   d	S )z(Detailed representation of the exceptionzAPIException(message='z', status_code=z
, module='z', request_id='z'))r
   r   r   r   r   s    r   __repr__zAPIException.__repr__/   sI     %T\\N 3++, -{{m $??+2/	
r   )zSomething went wrong!i  NNN)__name__
__module____qualname____doc__strintr   r   r   r   r   r   r!   __classcell__r   s   @r   r	   r	      s     /IM!!%'' ' T#s(^T$sCx.%93>?$F	'
 d
' $J'6> >
# 
r   r	   c            
       X     e Zd ZdZ	 	 ddedeeeef   eeeef      ef   f fdZ	 xZ
S )ValidationExceptionzException for validation errorsr
   r   c                 ,    t        |   d|d|d| y )Ni  )r
   r   r    r   r   )r   r
   r   kwargsr   s       r   r   zValidationException.__init__<   s*     	 	
	
 		
r   )zValidation failedN)r"   r#   r$   r%   r&   r   r   r   r   r   r(   r)   s   @r   r+   r+   9   sK    ) +BF

 T#s(^T$sCx.%93>?
 
r   r+   c                   ,     e Zd ZdZ	 ddef fdZ xZS )NotFoundErrorz'Exception for resource not found errorsr
   c                 *    t        |   d|dd| y )Ni  r   r-   r.   r   r
   r/   r   s      r   r   zNotFoundError.__init__M   '    
 	 	
	
 	
r   )zResource not foundr"   r#   r$   r%   r&   r   r(   r)   s   @r   r1   r1   J   s    1 ,	
	
 	
r   r1   c                   ,     e Zd ZdZ	 ddef fdZ xZS )UnauthorizedErrorz1Exception for authentication/authorization errorsr
   c                 *    t        |   d|dd| y )Ni  r   r-   r.   r3   s      r   r   zUnauthorizedError.__init__\   r4   r   )zUnauthorized accessr5   r)   s   @r   r7   r7   Y   s    ; -	
	
 	
r   r7   c                   ,     e Zd ZdZ	 ddef fdZ xZS )ForbiddenErrorz%Exception for forbidden access errorsr
   c                 *    t        |   d|dd| y )Ni  r   r-   r.   r3   s      r   r   zForbiddenError.__init__k   r4   r   )zAccess forbiddenr5   r)   s   @r   r:   r:   h   s    / *	
	
 	
r   r:   c                   ,     e Zd ZdZ	 ddef fdZ xZS )ConflictErrorz&Exception for resource conflict errorsr
   c                 *    t        |   d|dd| y )Ni  r   r-   r.   r3   s      r   r   zConflictError.__init__z   r4   r   )zResource conflictr5   r)   s   @r   r=   r=   w   s    0 +	
	
 	
r   r=   c                   ,     e Zd ZdZ	 ddef fdZ xZS )InternalServerErrorz$Exception for internal server errorsr
   c                 *    t        |   d|dd| y )Ni  r   r-   r.   r3   s      r   r   zInternalServerError.__init__   r4   r   )zInternal server errorr5   r)   s   @r   r@   r@      s    . /	
	
 	
r   r@   c            	       @     e Zd ZdZ	 	 ddedededz  def fdZ xZS )	PayrixApiErrorzzException for Payrix API non-2xx responses.

    Contains Payrix-specific context fields required by our integration.
    Nr   payrix_error_bodyr   r
   c                 <    t         |   |||d|       || _        y )Npayrix)r
   r   r   r   r   )r   r   rD   )r   r   rD   r   r
   r   s        r   r   zPayrixApiError.__init__   s0     	##! 	 	
 "3r   )NzPayrix API error)	r"   r#   r$   r%   r'   r   r&   r   r(   r)   s   @r   rC   rC      sD     "&)33 3 $J	3
 3 3r   rC   N)r%   r   typingr   r   r   r   	Exceptionr	   r+   r1   r7   r:   r=   r@   rC   r-   r   r   <module>rI      sv     ) ).
9 .
b
, 
"
L 

 

\ 

L 

, 
3\ 3r   