|
4 | 4 | import base64 |
5 | 5 | import logging |
6 | 6 |
|
| 7 | +import zeep |
7 | 8 | from cryptography import x509 |
8 | 9 | from cryptography.hazmat.backends import default_backend |
9 | 10 | from cryptography.hazmat.primitives import serialization |
@@ -58,23 +59,43 @@ def send_webservice( |
58 | 59 | invoice_call = client.get_type("ns0:EnviarFacturaRequest")( |
59 | 60 | email, invoice_file, anexos |
60 | 61 | ) |
61 | | - response = client.service.enviarFactura(invoice_call) |
| 62 | + try: |
| 63 | + response = client.service.enviarFactura(invoice_call) |
| 64 | + except zeep.exceptions.Fault as err: |
| 65 | + raise ValidationError( |
| 66 | + self.env._("Connection with FACe returned error: %(error)s", error=err) |
| 67 | + ) from err |
62 | 68 | if response.resultado.codigo != "0": |
63 | 69 | raise ValidationError(response.resultado.descripcion) |
64 | 70 | return response |
65 | 71 |
|
66 | 72 | def consult_invoice(self, public_crt, private_key, invoice_number): |
67 | 73 | client = self._get_client(public_crt, private_key) |
68 | | - return client.service.consultarFactura(invoice_number) |
| 74 | + try: |
| 75 | + return client.service.consultarFactura(invoice_number) |
| 76 | + except zeep.exceptions.Fault as err: |
| 77 | + raise ValidationError( |
| 78 | + self.env._("Connection with FACe returned error: %(error)s", error=err) |
| 79 | + ) from err |
69 | 80 |
|
70 | 81 | def consult_invoices(self, public_crt, private_key, invoices): |
71 | 82 | client = self._get_client(public_crt, private_key) |
72 | 83 | request = client.get_type("ns0:ConsultarListadoFacturaRequest")(invoices) |
73 | | - return client.service.consultarListadoFacturas(request) |
| 84 | + try: |
| 85 | + return client.service.consultarListadoFacturas(request) |
| 86 | + except zeep.exceptions.Fault as err: |
| 87 | + raise ValidationError( |
| 88 | + self.env._("Connection with FACe returned error: %(error)s", error=err) |
| 89 | + ) from err |
74 | 90 |
|
75 | 91 | def cancel(self, public_crt, private_key, identifier, motive): |
76 | 92 | client = self._get_client(public_crt, private_key) |
77 | | - response = client.service.anularFactura(identifier, motive) |
| 93 | + try: |
| 94 | + response = client.service.anularFactura(identifier, motive) |
| 95 | + except zeep.exceptions.Fault as err: |
| 96 | + raise ValidationError( |
| 97 | + self.env._("Connection with FACe returned error: %(error)s", error=err) |
| 98 | + ) from err |
78 | 99 | if response.resultado.codigo != "0": |
79 | 100 | raise UserError( |
80 | 101 | self.env._( |
|
0 commit comments