diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f036922..9188fc85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,9 +76,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix compatibility issue with Requests >= 2.32.2 (#350). - Return HTTP/404 not found with meaningful error message when requesting unexisting node. -- gateway: catch generic `requests.exceptions.RequestException` when retrieving - information from agents to avoid `AttributeError` with more specific - exceptions on old versions on _Requests_ library (#391). +- gateway: + - Catch generic `requests.exceptions.RequestException` when retrieving + information from agents to avoid `AttributeError` with more specific + exceptions on old versions on _Requests_ library (#391). + - Catch `JSONDecodeError` from _simpleson_ external library and _json_ + standard library module not managed by Requests < 2.27. - frontend: Update dependencies to fix CVE-2024-45812 and CVE-2024-45811 (vite), CVE-2024-47068 (rollup). diff --git a/slurmweb/apps/gateway.py b/slurmweb/apps/gateway.py index 185409dd..01e231b8 100644 --- a/slurmweb/apps/gateway.py +++ b/slurmweb/apps/gateway.py @@ -14,7 +14,11 @@ from . import SlurmwebWebApp from ..views import SlurmwebAppRoute from ..views import gateway as views -from ..errors import SlurmwebConfigurationError, SlurmwebAgentError +from ..errors import ( + SlurmwebConfigurationError, + SlurmwebCompatJSONDecodeError, + SlurmwebAgentError, +) logger = logging.getLogger(__name__) @@ -86,6 +90,7 @@ def agents(self): agent = self._agent_info(url.geturl()) except ( requests.exceptions.RequestException, + SlurmwebCompatJSONDecodeError, SlurmwebAgentError, ) as err: logger.error( diff --git a/slurmweb/errors.py b/slurmweb/errors.py index 4c995219..6f320d5f 100644 --- a/slurmweb/errors.py +++ b/slurmweb/errors.py @@ -27,3 +27,19 @@ class SlurmwebCacheError(Exception): class SlurmwebMetricsDBError(Exception): pass + + +# Alias JSONDecodeError from simplejson external library and json standard library +# module to catch generically the error raised with Requests < 2.27 on old systems in +# presence of unexepected non-JSON responses. +# +# This is not needed with Requests >= 2.27 where the same logic is implemented with +# requests.exceptions.JSONDecodeError wildcard exception. For reference, see: +# https://github.com/psf/requests/pull/5856 + +try: + from simplejson import JSONDecodeError +except ImportError: + from json import JSONDecodeError + +SlurmwebCompatJSONDecodeError = JSONDecodeError