Ë
    a%9j—	  ã                   ód   — d dl Z d dlZd dlmZ d dlmZ  e j                  d«      Zdd„Z	d„ Z
d„ Zy)	é    N©ÚResponse)Úexception_handlerÚapic                 ó&   — t        | |||dœ| ¬«      S )z˜
    Standard API response wrapper.

    {
        "status_code": 200,
        "message": "...",
        "error": null,
        "data": {...}
    }
    ©Ústatus_codeÚmessageÚerrorÚdata©Ústatusr   )Úcoder
   r   r   s       ú&/var/www/html/truck-me/api/response.pyÚapi_responser   
   s'   € ô àØØØñ		
ð ôð ó    c                 ó`   — t        | «      j                  }| rt        | «      nd}|r|› d|› �S |S )z>Return exact error string for API response (safe for clients).Ú z: )ÚtypeÚ__name__Ústr)ÚexcÚexc_typeÚexc_msgs      r   Ú_format_exceptionr       s6   € ä�C‹y×!Ñ!€HÙŒc�#Œh 2€GÙ'.ˆhˆZ�r˜'˜Ð#Ð<°HÐ<r   c                 ó–  — t        | |«      }|�v|j                  }|j                  }dddddddœ}|j                  |d	«      }t	        |t
        «      r#d
|v rt        |«      dk(  rt        |d
   «      }d}n|}|||ddœ|_        |S t        | «      }t        j                  d|t        j                  «       «       t        dd	|ddœd¬«      S )zÍ
    Wrap ALL exceptions in the standard api_response envelope.
    DRF-handled exceptions get formatted; unhandled (e.g. DB errors) get caught
    and returned with exact error message in our format.
    NzBad request.z<Authentication credentials were not provided or are invalid.z2You do not have permission to perform this action.z%The requested resource was not found.zMethod not allowed.zToo many requests.)i�  i‘  i“  i”  i•  i­  zAn error occurred.Údetailé   r   zUnhandled API exception: %s
%siô  r   )Údrf_exception_handlerr	   r   ÚgetÚ
isinstanceÚdictÚlenr   r   Úloggerr   Ú	tracebackÚ
format_excr   )	r   ÚcontextÚresponser   r   Ú	_messagesr
   r   Ú	error_strs	            r   Úcustom_exception_handlerr+   '   sô   € ô % S¨'Ó2€HàÐØ×#Ñ#ˆØ�}‰}ˆàØOØEØ8Ø&Ø%ñ
ˆ	ð —-‘- Ð&:Ó;ˆÜ�dœDÔ! h°$Ñ&6¼3¸t»9Èº>Ü˜$˜x™.Ó)ˆGØ‰EàˆEàØØØñ	
ˆŒð ˆô " #Ó&€IÜ
‡L�LØ)ØÜ×ÑÓôô
 àØ+ØØñ		
ð ôð r   )NN)Úloggingr%   Úrest_framework.responser   Úrest_framework.viewsr   r   Ú	getLoggerr$   r   r   r+   © r   r   ú<module>r1      s2   ðÛ Û å ,Ý Kà	ˆ×	Ñ	˜5Ó	!€óò,=ó0r   