diff --git a/edi_webservice_oca/components/send.py b/edi_webservice_oca/components/send.py index e42e345f7b4..9060278218e 100644 --- a/edi_webservice_oca/components/send.py +++ b/edi_webservice_oca/components/send.py @@ -5,6 +5,10 @@ from odoo import _, exceptions from odoo.addons.component.core import Component +from urllib.error import HTTPError + +class EDIWebserviceSendHTTPException(HTTPError): + pass class EDIWebserviceSend(Component): @@ -27,7 +31,11 @@ def __init__(self, work_context): def send(self): method, pargs, kwargs = self._get_call_params() - return self.webservice_backend.call(method, *pargs, **kwargs) + try: + return self.webservice_backend.call(method, *pargs, **kwargs) + except HTTPError as err: + raise EDIWebserviceSendHTTPException(err.url, err.code, err.msg, err.hdrs, err.fp) + def _get_call_params(self): try: diff --git a/edi_webservice_oca/tests/test_send.py b/edi_webservice_oca/tests/test_send.py index f0660fb087a..41be3ab24fc 100644 --- a/edi_webservice_oca/tests/test_send.py +++ b/edi_webservice_oca/tests/test_send.py @@ -6,7 +6,7 @@ from odoo import exceptions from .common import TestEDIWebserviceBase - +from ..components.send import EDIWebserviceSendHTTPException class TestSend(TestEDIWebserviceBase): @classmethod @@ -112,3 +112,15 @@ def test_component_send(self): responses.calls[0].request.headers["Content-Type"], "application/xml" ) self.assertEqual(responses.calls[0].request.body, "This is a simple file") + + @responses.activate + def test_component_send_raise_http_error(self): + self.record.type_id.set_settings(self.settings2) + record = self.record.with_user(self.a_user) + backend = self.backend.with_user(self.a_user) + + url = "https://foo.test/push/here" + responses.add(responses.POST, url, status=404) + component = backend._get_component(record, "send") + with self.assertRaises(EDIWebserviceSendHTTPException): + component.send()