Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias BARKAT committed Jun 10, 2024
2 parents 360ede9 + 6269113 commit 95bc510
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
13 changes: 10 additions & 3 deletions edi_webservice_oca/components/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from requests.exceptions import HTTPError

from odoo import _, exceptions

from odoo.addons.component.core import Component

from ..exceptions import EDIWebserviceSendHTTPException


class EDIWebserviceSend(Component):
"""Generic component for webservice requests.
Expand All @@ -28,9 +32,12 @@ def __init__(self, work_context):

def send(self):
method, pargs, kwargs = self._get_call_params()
return self.webservice_backend.call(
method, *pargs, consumer_record=self.exchange_record, **kwargs
)
try:
return self.webservice_backend.call(
method, *pargs, consumer_record=self.exchange_record, **kwargs
)
except HTTPError as err:
raise EDIWebserviceSendHTTPException("EDI HTTP Error: %s" % err) from err

def _get_call_params(self):
try:
Expand Down
5 changes: 5 additions & 0 deletions edi_webservice_oca/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from requests.exceptions import HTTPError


class EDIWebserviceSendHTTPException(HTTPError):
"""Exception raised when an HTTP error occurs during a webservice call."""
13 changes: 13 additions & 0 deletions edi_webservice_oca/tests/test_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from odoo import exceptions

from ..exceptions import EDIWebserviceSendHTTPException
from .common import TestEDIWebserviceBase


Expand Down Expand Up @@ -112,3 +113,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 95bc510

Please sign in to comment.