Display error message when network is down
This commit is contained in:
parent
85be796276
commit
8e1cdb76f0
@ -40,17 +40,20 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
def getStationsData(self) -> dict:
|
def getStationsData(self) -> dict:
|
||||||
"""Get JSON data from API and convert it to dict."""
|
"""Get JSON data from API and convert it to dict."""
|
||||||
|
try:
|
||||||
resp = requests.get(API_URL)
|
resp = requests.get(API_URL)
|
||||||
if resp.status_code not in range(200, 299 + 1):
|
if resp.status_code not in range(200, 299 + 1):
|
||||||
|
raise requests.exceptions.ConnectionError()
|
||||||
|
else:
|
||||||
|
return json.loads(resp.text)
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
error_box = QMessageBox.critical(
|
error_box = QMessageBox.critical(
|
||||||
self,
|
self,
|
||||||
"Błąd",
|
"Błąd",
|
||||||
f"Błąd połączenia o kodzie: {resp.status_code}",
|
"Brak połączenia z serwerem.",
|
||||||
QMessageBox.Cancel,
|
QMessageBox.Cancel,
|
||||||
)
|
)
|
||||||
error_box.exec()
|
error_box.exec()
|
||||||
else:
|
|
||||||
return json.loads(resp.text)
|
|
||||||
|
|
||||||
def printGroups(self) -> None:
|
def printGroups(self) -> None:
|
||||||
"""Print groups (categories) in groupsListWidget."""
|
"""Print groups (categories) in groupsListWidget."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user