Skip to content

Commit 445707a

Browse files
authored
Avoid caching when API call fails (#164)
1 parent d70505a commit 445707a

File tree

15 files changed

+104
-0
lines changed

15 files changed

+104
-0
lines changed

lib/addons.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,21 @@ function bashio::addons() {
164164
info=$(bashio::cache.get 'addons.list')
165165
else
166166
info=$(bashio::api.supervisor GET "/addons" false)
167+
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
168+
bashio::log.error "Failed to get addons from Supervisor API"
169+
return "${__BASHIO_EXIT_NOK}"
170+
fi
167171
bashio::cache.set "addons.list" "${info}"
168172
fi
169173
else
170174
if bashio::cache.exists "addons.${slug}.info"; then
171175
info=$(bashio::cache.get "addons.${slug}.info")
172176
else
173177
info=$(bashio::api.supervisor GET "/addons/${slug}/info" false)
178+
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
179+
bashio::log.error "Failed to get addon info from Supervisor API"
180+
return "${__BASHIO_EXIT_NOK}"
181+
fi
174182
bashio::cache.set "addons.${slug}.info" "${info}"
175183
fi
176184
fi
@@ -1202,6 +1210,10 @@ function bashio::addon.stats() {
12021210
info=$(bashio::cache.get "addons.${slug}.stats")
12031211
else
12041212
info=$(bashio::api.supervisor GET "/addons/${slug}/stats" false)
1213+
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
1214+
bashio::log.error "Failed to get addon stats from Supervisor API"
1215+
return "${__BASHIO_EXIT_NOK}"
1216+
fi
12051217
bashio::cache.set "addons.${slug}.stats" "${info}"
12061218
fi
12071219

lib/audio.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ function bashio::audio() {
7777
info=$(bashio::cache.get 'audio.info')
7878
else
7979
info=$(bashio::api.supervisor GET /audio/info false)
80+
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
81+
bashio::log.error "Failed to get audio info from Supervisor API"
82+
return "${__BASHIO_EXIT_NOK}"
83+
fi
8084
bashio::cache.set 'audio.info' "${info}"
8185
fi
8286

@@ -147,6 +151,10 @@ function bashio::audio.stats() {
147151
info=$(bashio::cache.get 'audio.stats')
148152
else
149153
info=$(bashio::api.supervisor GET /audio/stats false)
154+
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
155+
bashio::log.error "Failed to get audio stats from Supervisor API"
156+
return "${__BASHIO_EXIT_NOK}"
157+
fi
150158
bashio::cache.set 'audio.stats' "${info}"
151159
fi
152160

lib/cli.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ function bashio::cli() {
5151
info=$(bashio::cache.get 'cli.info')
5252
else
5353
info=$(bashio::api.supervisor GET /cli/info false)
54+
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
55+
bashio::log.error "Failed to get cli info from Supervisor API"
56+
return "${__BASHIO_EXIT_NOK}"
57+
fi
5458
bashio::cache.set 'cli.info' "${info}"
5559
fi
5660

@@ -113,6 +117,10 @@ function bashio::cli.stats() {
113117
info=$(bashio::cache.get 'cli.stats')
114118
else
115119
info=$(bashio::api.supervisor GET /cli/stats false)
120+
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
121+
bashio::log.error "Failed to get cli stats from Supervisor API"
122+
return "${__BASHIO_EXIT_NOK}"
123+
fi
116124
bashio::cache.set 'cli.stats' "${info}"
117125
fi
118126

lib/core.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ function bashio::core() {
9999
info=$(bashio::cache.get 'core.info')
100100
else
101101
info=$(bashio::api.supervisor GET /core/info false)
102+
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
103+
bashio::log.error "Failed to get core info from Supervisor API"
104+
return "${__BASHIO_EXIT_NOK}"
105+
fi
102106
bashio::cache.set 'core.info' "${info}"
103107
fi
104108

@@ -249,6 +253,10 @@ function bashio::core.stats() {
249253
info=$(bashio::cache.get 'core.stats')
250254
else
251255
info=$(bashio::api.supervisor GET /core/stats false)
256+
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
257+
bashio::log.error "Failed to get core stats from Supervisor API"
258+
return "${__BASHIO_EXIT_NOK}"
259+
fi
252260
bashio::cache.set 'core.stats' "${info}"
253261
fi
254262

lib/dns.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ function bashio::dns() {
7777
info=$(bashio::cache.get 'dns.info')
7878
else
7979
info=$(bashio::api.supervisor GET /dns/info false)
80+
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
81+
bashio::log.error "Failed to get dns info from Supervisor API"
82+
return "${__BASHIO_EXIT_NOK}"
83+
fi
8084
bashio::cache.set 'dns.info' "${info}"
8185
fi
8286

@@ -163,6 +167,10 @@ function bashio::dns.stats() {
163167
info=$(bashio::cache.get 'dns.stats')
164168
else
165169
info=$(bashio::api.supervisor GET /dns/stats false)
170+
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
171+
bashio::log.error "Failed to get dns stats from Supervisor API"
172+
return "${__BASHIO_EXIT_NOK}"
173+
fi
166174
bashio::cache.set 'dns.stats' "${info}"
167175
fi
168176

lib/hardware.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ function bashio::hardware() {
3131
info=$(bashio::cache.get 'hardware.info')
3232
else
3333
info=$(bashio::api.supervisor GET /hardware/info false)
34+
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
35+
bashio::log.error "Failed to get hardware info from Supervisor API"
36+
return "${__BASHIO_EXIT_NOK}"
37+
fi
3438
bashio::cache.set 'hardware.info' "${info}"
3539
fi
3640

lib/host.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ function bashio::host() {
6363
info=$(bashio::cache.get 'host.info')
6464
else
6565
info=$(bashio::api.supervisor GET /host/info false)
66+
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
67+
bashio::log.error "Failed to get host info from Supervisor API"
68+
return "${__BASHIO_EXIT_NOK}"
69+
fi
6670
bashio::cache.set 'host.info' "${info}"
6771
fi
6872

lib/info.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ function bashio::info() {
3131
info=$(bashio::cache.get 'info')
3232
else
3333
info=$(bashio::api.supervisor GET /info false)
34+
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
35+
bashio::log.error "Failed to get info from Supervisor API"
36+
return "${__BASHIO_EXIT_NOK}"
37+
fi
3438
bashio::cache.set 'info' "${info}"
3539
fi
3640

lib/multicast.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ function bashio::multicast() {
6868
info=$(bashio::cache.get 'multicast.info')
6969
else
7070
info=$(bashio::api.supervisor GET /multicast/info false)
71+
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
72+
bashio::log.error "Failed to get multicast info from Supervisor API"
73+
return "${__BASHIO_EXIT_NOK}"
74+
fi
7175
bashio::cache.set 'multicast.info' "${info}"
7276
fi
7377

@@ -130,6 +134,10 @@ function bashio::multicast.stats() {
130134
info=$(bashio::cache.get 'multicast.stats')
131135
else
132136
info=$(bashio::api.supervisor GET /multicast/stats false)
137+
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
138+
bashio::log.error "Failed to get multicast stats from Supervisor API"
139+
return "${__BASHIO_EXIT_NOK}"
140+
fi
133141
bashio::cache.set 'multicast.stats' "${info}"
134142
fi
135143

lib/network.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ function bashio::network() {
4141
info=$(bashio::cache.get 'network.info')
4242
else
4343
info=$(bashio::api.supervisor GET /network/info false)
44+
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
45+
bashio::log.error "Failed to get network info from Supervisor API"
46+
return "${__BASHIO_EXIT_NOK}"
47+
fi
4448
bashio::cache.set 'network.info' "${info}"
4549
fi
4650

@@ -105,6 +109,10 @@ function bashio::network.interface() {
105109
info=$(bashio::cache.get "network.interface.${interface}.info")
106110
else
107111
info=$(bashio::api.supervisor GET "/network/interface/${interface}/info" false)
112+
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
113+
bashio::log.error "Failed to get network interface info from Supervisor API"
114+
return "${__BASHIO_EXIT_NOK}"
115+
fi
108116
bashio::cache.set "network.interface.${interface}.info" "${info}"
109117
fi
110118

0 commit comments

Comments
 (0)