Skip to content

Commit

Permalink
Add error messages to convert script
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnmmeyer committed Mar 27, 2024
1 parent 9067ea7 commit 2701af4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions stylesheets/convert.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

import os, sys, platform, tempfile, subprocess, json
from urllib import request
from urllib import request, error

system = platform.system()
if system == "Windows":
Expand Down Expand Up @@ -37,9 +37,15 @@
}
req = request.Request(url, json.dumps(doc).encode("UTF-8"), headers=headers)

resp = request.urlopen(req)
with open(output, "wb") as f:
f.write(resp.read())
try:
resp = request.urlopen(req)
with open(output, "wb") as f:
f.write(resp.read())
except error.URLError as e:
code = getattr(e, "code", "no error code")
print(f"Server unreachable: {e.reason} ({code}).", file=sys.stderr)
print(f"Please retry in a few minutes. If this persists, contact the data manager.", file=sys.stderr)
sys.exit(1)

# We do not add check_output=True to the following because Windows returns
# EXIT_FAILURE even on success, for some reason.
Expand Down

0 comments on commit 2701af4

Please sign in to comment.