o
    }h                     @   s   d dl 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 d dlmZ G dd	 d	eZejd
ejdejdejdejdejdejdejdejdi	ZdefddZdd ZdS )    N)logger)APIException)fail_response)exception_handlerstatus)Responsec                       s*   e Zd ZdZdZdZd fdd	Z  ZS )CustomAPIExceptioni  zBad requestbad_requestNc                    s.   |d ur|| _ t|d t |p| j d S )Nz>>>>>>>>>>>>>>>>>>>>>)status_codeprintsuper__init__default_detail)selfdetailr   	__class__ /E:\0_Mansi\PremiumCrap\core\custom_exception.pyr      s   
zCustomAPIException.__init__)NN)__name__
__module____qualname__r   r   default_coder   __classcell__r   r   r   r   r	   
   s
    r	   zBad request.zAuthentication required.zPermission denied.zResource not found.zMethod not allowed.zNot acceptable.zUnsupported media type.zToo many requests.zInternal server error.returnc                 C   s   t | tr-g }|  D ]\}}t |ttfr!|D ]}||  q||  qd|S t | ttfr>ddd | D S t| S )Nz | c                 s   s    | ]}t |V  qd S )N)str).0mr   r   r   	<genexpr>0   s    z)combine_error_messages.<locals>.<genexpr>)
isinstancedictitemslisttupleappendjoinr   )errorspartsfieldZmsgsmsgr   r   r   combine_error_messages#   s   

r+   c                 C   s  t | |}|dd }|dd }|d ur|j}|j}td| d|r'|jjnd d|  d|r2|jnd d	| 
 t	|t
oId
|v oIt	|d
 t}t	|t
tfoS| }|ret|p_t|d}	|}
d }n*t	|t
ro|d
n|}|rwt|nt|d}	d }
t| dd }|d urd|ind }t||	|
|_|S td|dd d|  d|r|jnd dt   tttjtd tjdS )NviewrequestzHandled Exception [z] in ZUnknownViewz: z	 | Path: ZUnknownPathz	 | Data: r   zRequest failed.waitZ
retryAfterzUnhandled Exception in z
Path: z
Traceback: i  r   )drf_exception_handlergetr   datar   errorr   r   pathr    r!   r   r#   r+   DEFAULT_MESSAGESgetattrr   critical	traceback
format_excr   r   HTTP_500_INTERNAL_SERVER_ERROR)exccontextresponser,   r-   coder1   Zis_detail_strZis_structured_errorsmessager'   extrar   r.   r   r   r   custom_exception_handler4   sP   
	r@   )r7   core.loggerr   Zrest_framework.exceptionsr   core.responser   rest_framework.viewsr   r/   rest_frameworkr   rest_framework.responser   r	   HTTP_400_BAD_REQUESTHTTP_401_UNAUTHORIZEDHTTP_403_FORBIDDENHTTP_404_NOT_FOUNDHTTP_405_METHOD_NOT_ALLOWEDHTTP_406_NOT_ACCEPTABLEHTTP_415_UNSUPPORTED_MEDIA_TYPEHTTP_429_TOO_MANY_REQUESTSr9   r4   r   r+   r@   r   r   r   r   <module>   s(    