Skip to content

Commit

Permalink
Avoid using requests's JSONDecodeError
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
dlax committed Oct 13, 2023
1 parent a8c4a31 commit 6ee8db1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion check_patroni/types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from typing import Any, Callable, List, Optional, Tuple, Union
from urllib.parse import urlparse

Expand Down Expand Up @@ -71,7 +72,7 @@ def rest_api(self, service: str) -> Any:

try:
return r.json()
except requests.exceptions.JSONDecodeError:
except (json.JSONDecodeError, ValueError):
return None
raise nagiosplugin.CheckError("Connection failed for all provided endpoints")

Expand Down

0 comments on commit 6ee8db1

Please sign in to comment.