catching grpc error on setup, displaying error dialog and exiting app

This commit is contained in:
Blake Harnden 2019-12-09 16:23:09 -08:00
parent c36a72bc16
commit 088a69d9d9
2 changed files with 32 additions and 19 deletions

View file

@ -98,6 +98,9 @@ class Application(tk.Frame):
def save_config(self):
appconfig.save(self.guiconfig)
def close(self):
self.master.destroy()
if __name__ == "__main__":
log_format = "%(asctime)s - %(levelname)s - %(module)s:%(funcName)s - %(message)s"

View file

@ -6,6 +6,9 @@ import logging
import os
import time
from pathlib import Path
from tkinter import messagebox
import grpc
from core.api.grpc import client, core_pb2
from coretk import appconfig
@ -386,28 +389,35 @@ class CoreClient:
:return: existing sessions
"""
self.client.connect()
try:
self.client.connect()
# get service information
response = self.client.get_services()
for service in response.services:
group_services = self.services.setdefault(service.group, set())
group_services.add(service.name)
# get service information
response = self.client.get_services()
for service in response.services:
group_services = self.services.setdefault(service.group, set())
group_services.add(service.name)
# if there are no sessions, create a new session, else join a session
response = self.client.get_sessions()
logging.info("current sessions: %s", response)
sessions = response.sessions
if len(sessions) == 0:
self.create_new_session()
else:
dialog = SessionsDialog(self.app, self.app)
dialog.show()
# if there are no sessions, create a new session, else join a session
response = self.client.get_sessions()
logging.info("current sessions: %s", response)
sessions = response.sessions
if len(sessions) == 0:
self.create_new_session()
else:
dialog = SessionsDialog(self.app, self.app)
dialog.show()
response = self.client.get_service_defaults(self.session_id)
self.default_services = {
x.node_type: set(x.services) for x in response.defaults
}
response = self.client.get_service_defaults(self.session_id)
self.default_services = {
x.node_type: set(x.services) for x in response.defaults
}
except grpc.RpcError as e:
if e.code() == grpc.StatusCode.UNAVAILABLE:
messagebox.showerror("Server Error", e.details())
else:
messagebox.showerror("GRPC Error", e.details())
self.app.close()
def get_session_state(self):
response = self.client.get_session(self.session_id)