diff --git a/swh/core/api/__init__.py b/swh/core/api/__init__.py --- a/swh/core/api/__init__.py +++ b/swh/core/api/__init__.py @@ -84,6 +84,13 @@ return dec +class APIError(Exception): + """API Error""" + def __str__(self): + return ('An unexpected error occurred in the backend: {}' + .format(self.args)) + + class MetaSWHRemoteAPI(type): """Metaclass for SWHRemoteAPI, which adds a method for each endpoint of the database it is designed to access. @@ -141,9 +148,14 @@ This backend class will never be instantiated, it only serves as a template.""" - def __init__(self, api_exception, url, + api_exception = APIError + """The exception class to raise in case of communication error with + the server.""" + + def __init__(self, url, api_exception=None, timeout=None, chunk_size=4096, **kwargs): - self.api_exception = api_exception + if api_exception: + self.api_exception = api_exception base_url = url if url.endswith('/') else url + '/' self.url = base_url self.session = requests.Session() diff --git a/swh/core/tests/test_api.py b/swh/core/tests/test_api.py --- a/swh/core/tests/test_api.py +++ b/swh/core/tests/test_api.py @@ -74,7 +74,7 @@ super().__init__(*args, **kwargs) self.session.mount('mock', adapter) - c = Testclient('foo', 'mock://example.com/') + c = Testclient(url='mock://example.com/') res = c.test_endpoint('spam') self.assertEqual(nb_http_calls, 1)