mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-16 07:19:57 +00:00
suppress status errors also if option is set
This commit is contained in:
@ -40,6 +40,7 @@ class WebClient(Client, LazyLogging):
|
||||
|
||||
Attributes:
|
||||
address(str): address of the web service
|
||||
suppress_errors(bool): suppress logging errors (e.g. if no web server available)
|
||||
user(User | None): web service user descriptor
|
||||
"""
|
||||
|
||||
@ -54,6 +55,7 @@ class WebClient(Client, LazyLogging):
|
||||
self.user = User.from_option(
|
||||
configuration.get("web", "username", fallback=None),
|
||||
configuration.get("web", "password", fallback=None))
|
||||
self.suppress_errors = configuration.getboolean("settings", "suppress_http_log_errors", fallback=False)
|
||||
|
||||
self.__session = self._create_session(use_unix_socket=use_unix_socket)
|
||||
|
||||
@ -106,9 +108,13 @@ class WebClient(Client, LazyLogging):
|
||||
"""
|
||||
try:
|
||||
yield
|
||||
except requests.HTTPError as e:
|
||||
except requests.RequestException as e:
|
||||
if self.suppress_errors:
|
||||
return
|
||||
self.logger.exception("could not perform http request: %s", exception_response_text(e))
|
||||
except Exception:
|
||||
if self.suppress_errors:
|
||||
return
|
||||
self.logger.exception("could not perform http request")
|
||||
|
||||
def _create_session(self, *, use_unix_socket: bool) -> requests.Session:
|
||||
|
@ -175,12 +175,12 @@ def enum_values(enum: type[Enum]) -> list[str]:
|
||||
return [str(key.value) for key in enum] # explicit str conversion for typing
|
||||
|
||||
|
||||
def exception_response_text(exception: requests.exceptions.HTTPError) -> str:
|
||||
def exception_response_text(exception: requests.exceptions.RequestException) -> str:
|
||||
"""
|
||||
safe response exception text generation
|
||||
|
||||
Args:
|
||||
exception(requests.exceptions.HTTPError): exception raised
|
||||
exception(requests.exceptions.RequestException): exception raised
|
||||
|
||||
Returns:
|
||||
str: text of the response if it is not None and empty string otherwise
|
||||
|
Reference in New Issue
Block a user