Avoid using requests's JSONDecodeError
This exception is only present in "recent" version of requests, typically not in the version distributed by Debian bullseye. Since requests' JSONDecodeError is in general a subclass of json.JSONDecodeError, we use the latter, but also handle the plain ValueError (which json.JSONDecodeError is a subclass of) because requests might use simplejson (which uses its own JSONDecodeError, also a subclass of ValueError).
This commit is contained in:
parent
a8c4a3125d
commit
6ee8db1df2
|
@ -6,6 +6,9 @@
|
|||
|
||||
### Fixed
|
||||
|
||||
* Add compatibility with [requests](https://requests.readthedocs.io)
|
||||
version 2.25 and higher.
|
||||
|
||||
### Misc
|
||||
|
||||
* Improve test coverage by running an HTTP server to fake the Patroni API (#55
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import json
|
||||
from typing import Any, Callable, List, Optional, Tuple, Union
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
@ -71,7 +72,7 @@ class PatroniResource(nagiosplugin.Resource):
|
|||
|
||||
try:
|
||||
return r.json()
|
||||
except requests.exceptions.JSONDecodeError:
|
||||
except (json.JSONDecodeError, ValueError):
|
||||
return None
|
||||
raise nagiosplugin.CheckError("Connection failed for all provided endpoints")
|
||||
|
||||
|
|
Loading…
Reference in a new issue