From 7b69aabaf36c7e3b838f3c175c7113203a7096d6 Mon Sep 17 00:00:00 2001 From: Kevin Rosales Date: Sat, 4 Oct 2025 10:08:26 -0600 Subject: [PATCH] Tackeo de errores --- api/api_v2/modules/coves/services.py | 30 +++++++++++++++++------ api/api_v2/modules/partidas/services.py | 30 +++++++++++++++++------ api/api_v2/modules/pedimentos/services.py | 24 ++++++++++++------ api/api_v2/modules/remesas/services.py | 24 ++++++++++++------ utils/helpers.py | 2 ++ 5 files changed, 81 insertions(+), 29 deletions(-) diff --git a/api/api_v2/modules/coves/services.py b/api/api_v2/modules/coves/services.py index 7f878de..9bcc058 100644 --- a/api/api_v2/modules/coves/services.py +++ b/api/api_v2/modules/coves/services.py @@ -86,14 +86,28 @@ async def consume_ws_get_cove(**kwargs): # Enviar documento _file_name = f"vu_COVE_{pedimento_app}_{cove}.xml" - document_response = await coves_rest_controller.post_document( - soap_response=soap_response, - organizacion=kwargs.get('pedimento').get('organizacion'), - pedimento=kwargs.get('pedimento').get('id'), - file_name=_file_name, - document_type=8, - ) - + try: + if soap_error(soap_response): + document_response = await coves_rest_controller.post_document( + soap_response=soap_response, + organizacion=kwargs.get('pedimento').get('organizacion'), + pedimento=kwargs.get('pedimento').get('id'), + file_name=f"vu_COVE_{pedimento_app}_{cove}_ERROR.xml", + document_type=10, + ) + raise Exception("Error en la respuesta del servicio SOAP") + else: + document_response = await coves_rest_controller.post_document( + soap_response=soap_response, + organizacion=kwargs.get('pedimento').get('organizacion'), + pedimento=kwargs.get('pedimento').get('id'), + file_name=_file_name, + document_type=8, + ) + except Exception as e: + logger.error(f"Error detectado en la respuesta SOAP: {str(e)}") + raise Exception(f"Error en la respuesta SOAP: {str(e)}") + logger.info("Documento enviado, actualizando status de COVE") # Actualizar status del COVE diff --git a/api/api_v2/modules/partidas/services.py b/api/api_v2/modules/partidas/services.py index d37dab9..4318c93 100644 --- a/api/api_v2/modules/partidas/services.py +++ b/api/api_v2/modules/partidas/services.py @@ -76,13 +76,29 @@ async def consume_ws_get_partida(**kwargs): # Enviar documento _file_name = f"vu_PT_{pedimento_app}_{partida.get('numero', '')}.xml" - document_response = await partida_rest_controller.post_document( - soap_response=soap_response, - organizacion=kwargs.get('pedimento').get('organizacion'), - pedimento=kwargs.get('pedimento').get('id'), - file_name=_file_name, - document_type=1, - ) + try: + if soap_error(soap_response): + document_response = await partida_rest_controller.post_document( + soap_response=soap_response, + organizacion=kwargs.get('pedimento').get('organizacion'), + pedimento=kwargs.get('pedimento').get('id'), + file_name=f"vu_PT_{pedimento_app}_{partida.get('numero', '')}_ERROR.xml", + document_type=10, + ) + raise Exception("Error en la respuesta del servicio SOAP") + else: + document_response = await partida_rest_controller.post_document( + soap_response=soap_response, + organizacion=kwargs.get('pedimento').get('organizacion'), + pedimento=kwargs.get('pedimento').get('id'), + file_name=_file_name, + document_type=1, + ) + + except Exception as e: + logger.error(f"Error detectado en la respuesta SOAP: {str(e)}") + raise Exception(f"Error en la respuesta SOAP: {str(e)}") + logger.info("Documento enviado, actualizando status de Partida") diff --git a/api/api_v2/modules/pedimentos/services.py b/api/api_v2/modules/pedimentos/services.py index 3a68dd9..c8a20a3 100644 --- a/api/api_v2/modules/pedimentos/services.py +++ b/api/api_v2/modules/pedimentos/services.py @@ -88,13 +88,23 @@ async def consume_ws_get_pedimento_completo(**kwargs) -> Dict[str, Any]: # Enviar documento try: - document_response = await pedimento_rest_controller.post_document( - soap_response=soap_response, - organizacion=pedimento_data.get('organizacion'), - pedimento=pedimento_data.get('id'), - file_name=file_name, - document_type=2, - ) + if soap_error(soap_response): + document_response = await pedimento_rest_controller.post_document( + soap_response=None, + organizacion=pedimento_data.get('organizacion'), + pedimento=pedimento_data.get('id'), + file_name=f"vu_PC_{pedimento_data.get('pedimento_app', 'unknown')}_ERROR.xml", + document_type=10, + ) + raise HTTPException(status_code=500, detail="Error en la respuesta del servicio SOAP") + else: + document_response = await pedimento_rest_controller.post_document( + soap_response=soap_response, + organizacion=pedimento_data.get('organizacion'), + pedimento=pedimento_data.get('id'), + file_name=file_name, + document_type=2, + ) except Exception as e: logger.error(f"Error al enviar documento: {e}") raise HTTPException(status_code=500, detail="Error al guardar documento") diff --git a/api/api_v2/modules/remesas/services.py b/api/api_v2/modules/remesas/services.py index 0549280..4e076c0 100644 --- a/api/api_v2/modules/remesas/services.py +++ b/api/api_v2/modules/remesas/services.py @@ -91,13 +91,23 @@ async def obtener_remesa(**kwargs) -> Dict[str, Any]: # Enviar documento try: - document_response = await remesa_rest_controller.post_document( - soap_response=soap_response, - organizacion=pedimento_data.get('organizacion'), - pedimento=pedimento_data.get('id'), - file_name=file_name, - document_type=2, - ) + if soap_error(soap_response): + document_response = await remesa_rest_controller.post_document( + soap_response=None, + organizacion=pedimento_data.get('organizacion'), + pedimento=pedimento_data.get('id'), + file_name=f"vu_RM_{pedimento_data.get('pedimento_app', 'unknown')}_ERROR.xml", + document_type=10, + ) + raise HTTPException(status_code=500, detail="Error en la respuesta del servicio SOAP") + else: + document_response = await remesa_rest_controller.post_document( + soap_response=soap_response, + organizacion=pedimento_data.get('organizacion'), + pedimento=pedimento_data.get('id'), + file_name=file_name, + document_type=3, + ) except Exception as e: logger.error(f"Error al enviar documento: {e}") raise HTTPException(status_code=500, detail="Error al guardar documento") diff --git a/utils/helpers.py b/utils/helpers.py index 7e2c826..ed44f0c 100644 --- a/utils/helpers.py +++ b/utils/helpers.py @@ -8,6 +8,8 @@ def soap_error(soap_response): # Testeado Returns: bool: True si no hay errores, False en caso contrario """ + if 'true' in soap_response.text: + return True if 'true' in soap_response.text: return True