Adding better error output for when loading remote configurations goes wrong. (#1415)

This commit is contained in:
Anton Hvornum 2022-08-10 11:02:24 +02:00 committed by GitHub
parent 6213560a05
commit 242f8076bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -12,6 +12,7 @@ import time
import re
import urllib.parse
import urllib.request
import urllib.error
import pathlib
from datetime import datetime, date
from typing import Callable, Optional, Dict, Any, List, Union, Iterator, TYPE_CHECKING
@ -548,8 +549,12 @@ def json_stream_to_structure(configuration_identifier : str, stream :str, target
parsed_url = urllib.parse.urlparse(stream)
if parsed_url.scheme: # The stream is in fact a URL that should be grabbed
with urllib.request.urlopen(urllib.request.Request(stream, headers={'User-Agent': 'ArchInstall'})) as response:
target.update(json.loads(response.read()))
try:
with urllib.request.urlopen(urllib.request.Request(stream, headers={'User-Agent': 'ArchInstall'})) as response:
target.update(json.loads(response.read()))
except urllib.error.HTTPError as error:
log(f"Could not load {configuration_identifier} via {parsed_url} due to: {error}", level=logging.ERROR, fg="red")
return False
else:
if pathlib.Path(stream).exists():
try: