Skip to content
This repository was archived by the owner on Oct 28, 2023. It is now read-only.

Commit a31ff04

Browse files
authored
Merge pull request SHA2017-badge#194 from SHA2017-badge/installer_graceful_failure
Use a timeout on fetching data, and handle failures gracefully.
2 parents 2d3efae + 4aac2ef commit a31ff04

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

esp32/modules/installer.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ugfx, badge, network, gc, time, urequests, appglue
1+
import ugfx, badge, network, gc, time, urequests, appglue, sys
22

33
# SHA2017 Badge installer
44
# V2 Thomas Roos
@@ -71,10 +71,19 @@ def list_apps(slug):
7171
ugfx.flush(ugfx.LUT_FULL)
7272

7373
try:
74-
f = urequests.get("https://badge.sha2017.org/eggs/category/%s/json" % slug)
75-
packages = f.json()
76-
finally:
77-
f.close()
74+
f = urequests.get("https://badge.sha2017.org/eggs/category/%s/json" % slug, timeout=30)
75+
try:
76+
packages = f.json()
77+
finally:
78+
f.close()
79+
except BaseException as e:
80+
print("[Installer] Failed to download list of eggs:")
81+
sys.print_exception(e)
82+
text.text("Download failed")
83+
ugfx.flush(ugfx.LUT_FULL)
84+
list_categories()
85+
gc.collect()
86+
return
7887

7988
for package in packages:
8089
options.add_item("%s rev. %s" % (package["name"], package["revision"]))
@@ -145,7 +154,7 @@ def list_categories():
145154
ugfx.input_init()
146155
draw_msg('Getting categories')
147156
try:
148-
f = urequests.get("https://badge.sha2017.org/eggs/categories/json")
157+
f = urequests.get("https://badge.sha2017.org/eggs/categories/json", timeout=30)
149158
categories = f.json()
150159
except:
151160
draw_msg('Failed!')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy