From d07a26d3244ea73623c3a049e4337a0e7d67a471 Mon Sep 17 00:00:00 2001 From: benoit Date: Mon, 21 Aug 2023 14:56:02 +0200 Subject: [PATCH] Fix tests in a more pytonic way as proposed by @dlax --- check_patroni/types.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/check_patroni/types.py b/check_patroni/types.py index 258b487..16789a7 100644 --- a/check_patroni/types.py +++ b/check_patroni/types.py @@ -69,7 +69,10 @@ class PatroniResource(nagiosplugin.Resource): f"Failed to connect to {endpoint}/{service} status code {r.status_code}" ) - return r.json() if r.text else None + try: + return r.json() + except requests.exceptions.JSONDecodeError: + return None raise nagiosplugin.CheckError("Connection failed for all provided endpoints")