Skip to content

Commit

Permalink
Both engines raise a BfabricRequestError if the endpoint was not fo…
Browse files Browse the repository at this point in the history
…und.
  • Loading branch information
leoschwarz committed Aug 27, 2024
1 parent 25c25d9 commit a676e7a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion bfabric/engine/engine_suds.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import copy
from typing import Any, TYPE_CHECKING

import suds.transport
from suds import MethodNotFound
from suds.client import Client

Expand Down Expand Up @@ -85,7 +86,13 @@ def delete(self, endpoint: str, id: int | list[int], auth: BfabricAuth) -> Resul
def _get_suds_service(self, endpoint: str) -> ServiceProxy:
"""Returns a SUDS service for the given endpoint. Reuses existing instances when possible."""
if endpoint not in self._cl:
self._cl[endpoint] = Client(f"{self._base_url}/{endpoint}?wsdl", cache=None)
try:
self._cl[endpoint] = Client(f"{self._base_url}/{endpoint}?wsdl", cache=None)
except suds.transport.TransportError as error:
if error.httpcode == 404:
msg = f"Non-existent endpoint {repr(endpoint)} or the configured B-Fabric instance was not found."
raise BfabricRequestError(msg) from error
raise
return self._cl[endpoint].service

def _convert_results(self, response: Any, endpoint: str) -> ResultContainer:
Expand Down
9 changes: 8 additions & 1 deletion bfabric/engine/engine_zeep.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import copy
from typing import Any, TYPE_CHECKING

import requests
import zeep
from zeep.helpers import serialize_object

Expand Down Expand Up @@ -109,7 +110,13 @@ def delete(self, endpoint: str, id: int | list[int], auth: BfabricAuth) -> Resul

def _get_client(self, endpoint: str) -> zeep.Client:
if endpoint not in self._cl:
self._cl[endpoint] = zeep.Client(f"{self._base_url}/{endpoint}?wsdl")
try:
self._cl[endpoint] = zeep.Client(f"{self._base_url}/{endpoint}?wsdl")
except requests.exceptions.HTTPError as error:
if error.response is not None and error.response.status_code == 404:
msg = f"Non-existent endpoint {repr(endpoint)} or the configured B-Fabric instance was not found."
raise BfabricRequestError(msg) from error
raise
return self._cl[endpoint]

def _convert_results(self, response: Any, endpoint: str) -> ResultContainer:
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Versioning currently follows `X.Y.Z` where

- `bfabric_read.py` prints non-output information exclusively through logger and does not restrict entity types anymore.
- `bfabric_delete.py` accepts multiple ids at once and does not restrict entity types anymore.
- Both engines raise a `BfabricRequestError` if the endpoint was not found.

### Removed

Expand Down

0 comments on commit a676e7a

Please sign in to comment.