File size: 2,505 Bytes
095b5f1
 
5ea29d8
 
756fca0
095b5f1
 
 
756fca0
ab34606
095b5f1
 
 
 
 
756fca0
f8e2c8b
ab34606
f8e2c8b
 
ab34606
 
 
 
 
f8e2c8b
 
 
 
 
 
 
ab34606
 
 
 
095b5f1
 
 
85dd209
ab34606
85dd209
 
f8e2c8b
 
756fca0
f9a1a18
ab34606
756fca0
5ea29d8
ab34606
2213315
756fca0
 
 
 
095b5f1
 
ab34606
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# myapp/exception_handler.py

from datetime import datetime
import pytz
from typing import Any, Dict, Union
from rest_framework.views import exception_handler
import logging
from _utils.bubble_integrations.enviar_resposta_final import enviar_resposta_final
from gerar_documento.serializer import GerarDocumentoSerializerData
from setup.logging import Axiom

logger = logging.getLogger(__name__)


def custom_exception_handler(exc, context):
    if context:
        serializer: Dict = context["view"].serializer
        axiom_instance: Axiom = context["view"].axiom_instance
    else:
        serializer = {}
        axiom_instance: Axiom = Axiom()
    axiom_instance.send_axiom_error(
        "---------------- CHEGOU NA FUNÇÃO PERSONALIZADA DE ERRO ----------------"
    )
    axiom_instance.send_axiom_error("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,
    )
    axiom_instance.send_axiom_error(
        f"resposta_bubble.status_code: {resposta_bubble.status_code}"
    )
    axiom_instance.send_axiom_error(f"resposta_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":
        axiom_instance.send_axiom_error(f"Validation error: {response.data}")
        logger.error(f"Validation error: {response.data}")

    return response


def custom_exception_handler_without_api_handler(
    error, serializer: Union[GerarDocumentoSerializerData, Any], axiom_instace: Axiom
):
    bahia_tz = pytz.timezone("America/Bahia")
    axiom_instace.send_axiom_error("INICIANDO RESPOSTA DE ERRO PARA O BUBBLE")
    resposta_bubble = enviar_resposta_final(
        serializer.doc_id,
        serializer.form_response_id,
        serializer.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,
    )
    axiom_instace.send_axiom_error(
        f"resposta_bubble.status_code: {resposta_bubble.status_code}"
    )
    axiom_instace.send_axiom_error(f"resposta_bubble.text: {resposta_bubble.text}")
    axiom_instace.send_axiom_error(f"------------ MOTIVO DO ERRO -----------: {error}")