Skip to content

Commit

Permalink
Don't throw exceptions on HTTP error
Browse files Browse the repository at this point in the history
  • Loading branch information
sheyabernstein committed Feb 29, 2024
1 parent 32f43ad commit 753b807
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ module.exports = NodeHelper.create({
if (config.showSources && config.sourcesCount > 0) {
if (config.showSources && !config.apiToken) {
Log.error(
`${this.name}: Can't load sources because the apiKey is not set.`,
`${this.name}: Can't load sources because the apiKey is not set.`
);
} else {
this.getPiholeData(
config,
{ getQuerySources: config.sourcesCount },
"PIHOLE_SOURCES",
"PIHOLE_SOURCES"
);
}
}
Expand Down Expand Up @@ -66,7 +66,7 @@ module.exports = NodeHelper.create({
try {
const response = await fetch(url, { headers });
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
Log.error(`${this.name}: HTTP Error ${response.status}`);
}
if (
response.headers
Expand All @@ -76,12 +76,16 @@ module.exports = NodeHelper.create({
const data = await response.json();
self.sendSocketNotification(notification, data);
} else {
throw new Error(
`Expected JSON but received ${response.headers.get("content-type")}`,
Log.error(
`${
this.name
}: Expected JSON but received ${response.headers.get(
"content-type"
)}`
);
}
} catch (error) {
Log.error(self.name + " ERROR:", error);
Log.error(`${this.name}: ${error}`);
}
},
}
});

0 comments on commit 753b807

Please sign in to comment.