Skip to content

Commit

Permalink
[ADD] EDIWebserviceSendHTTPException to catch http error form edi_web…
Browse files Browse the repository at this point in the history
…service_oca
  • Loading branch information
Matthias BARKAT committed Jun 9, 2024
1 parent 5c39f74 commit 490942c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 9 additions & 1 deletion edi_webservice_oca/components/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down
14 changes: 13 additions & 1 deletion edi_webservice_oca/tests/test_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from odoo import exceptions

from .common import TestEDIWebserviceBase

from ..components.send import EDIWebserviceSendHTTPException

class TestSend(TestEDIWebserviceBase):
@classmethod
Expand Down Expand Up @@ -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()

0 comments on commit 490942c

Please sign in to comment.