Commit b30642d4 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update InvenioStore.interogate to handle properly RequestException and timeout.

parent 4d6064dc
......@@ -8,7 +8,6 @@ import time
from .exception import CdsException
from requests.adapters import HTTPAdapter
from requests.exceptions import ConnectionError, HTTPError
CDS_SEARCH_KEYS = ("req", "cc", "c", "ec", "p", "f", "rg", "sf", "so", "sp",
......@@ -60,31 +59,28 @@ class InvenioStore(object):
# close the session
self._session.close()
def interogate(self, url, params=None):
def interogate(self, url, timeout=10, params=None):
"""Interrogate the store using the *URL*.
Args:
url (str): URL string
params (dict): parameters to be send with the URL
timeout (float):
timeout for the HTTP request
Returns:
str: the HTTP response
Raises:
CdsException:
when the server returns connection or HTTP error.
RequestException:
something went wrong within the HTTP dialog
"""
self._url = url
try:
r = self._session.get(url, params=params)
except ConnectionError as ce:
raise CdsException(str(ce))
except HTTPError as he:
raise CdsException(str(he))
r = self._session.get(url, timeout=timeout, params=params)
r.raise_for_status()
r.encoding = "utf-8"
return r.text
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment