Spaces:
Running
Running
luanpoppe
feat: convertendo texto final de markdown para html + melhorando custom exception handler
5ea29d8
| # myapp/exception_handler.py | |
| from datetime import datetime | |
| import pytz | |
| from typing import Dict | |
| from rest_framework.views import exception_handler | |
| import logging | |
| from _utils.bubble_integrations.enviar_resposta_final import enviar_resposta_final | |
| logger = logging.getLogger(__name__) | |
| def custom_exception_handler(exc, context): | |
| print("---------------- CHEGOU NA FUNÇÃO PERSONALIZADA DE ERRO ----------------") | |
| if (context): | |
| serializer: Dict = context["view"].serializer | |
| else: | |
| serializer = {} | |
| print("INICIANDO RESPOSTA DE ERRO PARA O BUBBLE") | |
| resposta_bubble = enviar_resposta_final( | |
| serializer.get("doc_id", ""), | |
| serializer.get("form_response_id", ""), | |
| serializer.get("version", ""), | |
| serializer.get("texto_completo", ""), | |
| True, | |
| ) | |
| print("\n\nresposta_bubble.status_code", resposta_bubble.status_code) | |
| print("\n\nresposta_bubble.text", resposta_bubble.text) | |
| # Call REST framework's default exception handler first | |
| response = exception_handler(exc, context) | |
| if response and str(response.status_code)[0] != "2": | |
| logger.error(f"Validation error: {response.data}") | |
| return response | |
| def custom_exception_handler_wihout_api_handler(error, serializer: Dict): | |
| bahia_tz = pytz.timezone("America/Bahia") | |
| print("INICIANDO RESPOSTA DE ERRO PARA O BUBBLE") | |
| resposta_bubble = enviar_resposta_final( | |
| serializer.get("doc_id", ""), | |
| serializer.get("form_response_id", ""), | |
| serializer.get("version", ""), | |
| f"------------ ERRO NO BACKEND ÀS {datetime.now(bahia_tz).strftime("%d/%m/%Y - %H:%M:%S")} ------------:\nMensagem de erro: {error} ", # serializer.get("texto_completo", ""), | |
| True, | |
| ) | |
| print("\n\nresposta_bubble.status_code", resposta_bubble.status_code) | |
| print("\n\nresposta_bubble.text", resposta_bubble.text) | |
| print("\n------------ MOTIVO DO ERRO -----------:", f"\n{error}") |