o
    ^5jº  ã                   @   sj  d dl Z d dlmZmZ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mZmZmZmZmZmZ d dlmZ eƒ  e  e¡Zeƒ Zeejd	d
d�Ze e¡dedede	fdd„ƒZe e¡dedede	fdd„ƒZ e e!¡dede!de	fdd„ƒZ"e #ej$¡ e #ej$¡ e #ej$¡ e #ej%¡ e #ej$¡ e #ej$¡ e #ej$¡ e #ej$¡ dS )é    N)ÚFastAPIÚHTTPExceptionÚRequestÚstatus)ÚRequestValidationError)ÚJSONResponse)Úget_settings)Úconfigure_logging)ÚencuestaÚeventsÚhealthÚinstallÚmbiaÚwebhookÚworkflow)Úcontrolled_errorz1.0.0z9API conversacional para Freshchat/Freshworks Automations.)ÚtitleÚversionÚdescriptionÚrequestÚexcÚreturnc                 Ã   s*   �t |jtƒr
|jnd}t|jt|ƒd�S )NzError HTTP.©Ústatus_codeÚcontent)Ú
isinstanceÚdetailÚstrr   r   r   )r   r   Úmessage© r   ú1/var/www/html/macrobase-freshchat-api/app/main.pyÚhttp_exception_handler   s   €þr!   c                 Ã   s2   �dd„ |  ¡ D ƒ}ttji tdƒ¥d|i¥d�S )Nc                 S   s*   g | ]}|  d ¡|  d¡|  d¡dœ‘qS )ÚlocÚmsgÚtype)r"   r#   r$   )Úget)Ú.0Úerrorr   r   r    Ú
<listcomp>"   s    üýÿz0validation_exception_handler.<locals>.<listcomp>z3El JSON enviado no cumple con el esquema requerido.Úvalidation_errorsr   )Úerrorsr   r   ÚHTTP_422_UNPROCESSABLE_ENTITYr   )r   r   r)   r   r   r    Úvalidation_exception_handler    s   €úÿþþr,   c                 Ã   s(   �t  d| j| jj¡ ttjtdƒd�S )NzUnhandled error on %s %su4   OcurriÃ³ un error tÃ©cnico al procesar la solicitud.r   )	ÚloggerÚ	exceptionÚmethodÚurlÚpathr   r   ÚHTTP_500_INTERNAL_SERVER_ERRORr   )r   r   r   r   r    Úunhandled_exception_handler3   s   €þr3   )&ÚloggingÚfastapir   r   r   r   Úfastapi.exceptionsr   Úfastapi.responsesr   Úapp.core.configr   Úapp.core.loggingr	   Úapp.routersr
   r   r   r   r   r   r   Ú!app.services.conversation_builderr   Ú	getLoggerÚ__name__r-   ÚsettingsÚapp_nameÚappÚexception_handlerr!   r,   Ú	Exceptionr3   Úinclude_routerÚrouterÚrender_routerr   r   r   r    Ú<module>   s<    $
ý