Skip to content

Commit 9b08b4d

Browse files
committed
improve error handling
Signed-off-by: Zen <[email protected]>
1 parent d5256c5 commit 9b08b4d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "json_exporter"
7-
version = "1.0.1"
7+
version = "1.0.2"
88
authors = [
99
{ name="Desultory", email="[email protected]" },
1010
]

src/json_exporter/json_endpoint.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ async def get_metrics(self, label_filter={}):
116116
try:
117117
await self.get_data()
118118
except JSONDecodeError:
119-
self.logger.error("[%s] Failed to decode JSON data: %s" % (self.name, self.json_data))
119+
if json_data := getattr(self, 'json_data', None):
120+
self.logger.error("[%s] Failed to decode JSON data: %s" % (self.name, json_data))
121+
else:
122+
self.logger.error("[%s] Failed to decode JSON data." % self.name)
120123
return
121124
await self.update_json_labels()
122125
await self.populate_metrics()

0 commit comments

Comments
 (0)