Fix for show errors

This commit is contained in:
Adolfo Gómez García 2021-06-19 15:26:05 +02:00
parent 6e60a66ae9
commit 9180d04aaf

View File

@ -53,7 +53,6 @@ from uds import VERSION
from UDSWindow import Ui_MainWindow from UDSWindow import Ui_MainWindow
class UDSClient(QtWidgets.QMainWindow): class UDSClient(QtWidgets.QMainWindow):
ticket: str = '' ticket: str = ''
@ -107,7 +106,7 @@ class UDSClient(QtWidgets.QMainWindow):
None, # type: ignore None, # type: ignore
'UDS Plugin Error', 'UDS Plugin Error',
'{}'.format(error), '{}'.format(error),
QtWidgets.QMessageBox.Ok QtWidgets.QMessageBox.Ok,
) )
self.withError = True self.withError = True
@ -142,7 +141,7 @@ class UDSClient(QtWidgets.QMainWindow):
self, self,
'Upgrade required', 'Upgrade required',
'A newer connector version is required.\nA browser will be opened to download it.', 'A newer connector version is required.\nA browser will be opened to download it.',
QtWidgets.QMessageBox.Ok QtWidgets.QMessageBox.Ok,
) )
webbrowser.open(e.downloadUrl) webbrowser.open(e.downloadUrl)
self.closeWindow() self.closeWindow()
@ -174,8 +173,8 @@ class UDSClient(QtWidgets.QMainWindow):
# Retry operation in ten seconds # Retry operation in ten seconds
QtCore.QTimer.singleShot(10000, self.getTransportData) QtCore.QTimer.singleShot(10000, self.getTransportData)
except Exception as e: except Exception as e:
logger.exception('Got exception on getTransportData') # logger.exception('Got exception on getTransportData')
raise e self.showError(e)
def start(self): def start(self):
""" """
@ -184,6 +183,7 @@ class UDSClient(QtWidgets.QMainWindow):
self.ui.info.setText('Initializing...') self.ui.info.setText('Initializing...')
QtCore.QTimer.singleShot(100, self.getVersion) QtCore.QTimer.singleShot(100, self.getVersion)
def endScript(): def endScript():
# Wait a bit before start processing ending sequence # Wait a bit before start processing ending sequence
time.sleep(3) time.sleep(3)
@ -224,18 +224,22 @@ def approveHost(hostName: str):
) )
if not approved: if not approved:
if QtWidgets.QMessageBox.warning( if (
QtWidgets.QMessageBox.warning(
None, # type: ignore None, # type: ignore
'ACCESS Warning', 'ACCESS Warning',
errorString, errorString,
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No # type: ignore QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, # type: ignore
) == QtWidgets.QMessageBox.Yes: )
== QtWidgets.QMessageBox.Yes
):
settings.setValue(hostName, True) settings.setValue(hostName, True)
approved = True approved = True
settings.endGroup() settings.endGroup()
return approved return approved
def sslError(hostname: str, serial): def sslError(hostname: str, serial):
settings = QSettings() settings = QSettings()
settings.beginGroup('ssl') settings.beginGroup('ssl')
@ -258,6 +262,7 @@ def sslError(hostname: str, serial):
settings.endGroup() settings.endGroup()
return approved return approved
def minimal(api: RestApi, ticket: str, scrambler: str): def minimal(api: RestApi, ticket: str, scrambler: str):
try: try:
logger.info('M1 Execution') logger.info('M1 Execution')
@ -269,7 +274,7 @@ def minimal(api: RestApi, ticket: str, scrambler: str):
None, # type: ignore None, # type: ignore
'Upgrade required', 'Upgrade required',
'A newer connector version is required.\nA browser will be opened to download it.', 'A newer connector version is required.\nA browser will be opened to download it.',
QtWidgets.QMessageBox.Ok QtWidgets.QMessageBox.Ok,
) )
webbrowser.open(e.downloadUrl) webbrowser.open(e.downloadUrl)
return 0 return 0
@ -285,15 +290,20 @@ def minimal(api: RestApi, ticket: str, scrambler: str):
QtWidgets.QMessageBox.warning( QtWidgets.QMessageBox.warning(
None, # type: ignore None, # type: ignore
'Service not ready', 'Service not ready',
'{}'.format('.\n'.join(str(e).split('.'))) + '\n\nPlease, retry again in a while.' , '{}'.format('.\n'.join(str(e).split('.')))
QtWidgets.QMessageBox.Ok + '\n\nPlease, retry again in a while.',
QtWidgets.QMessageBox.Ok,
) )
except Exception as e: except Exception as e:
logger.exception('Got exception on getTransportData') # logger.exception('Got exception on getTransportData')
raise e QtWidgets.QMessageBox.critical(
None, # type: ignore
'Error',
'{}'.format(str(e))
+ '\n\nPlease, retry again in a while.',
QtWidgets.QMessageBox.Ok,
)
except Exception:
logger.exception('Uncaught exception')
if __name__ == "__main__": if __name__ == "__main__":
logger.debug('Initializing connector') logger.debug('Initializing connector')
@ -340,9 +350,9 @@ if __name__ == "__main__":
sys.exit(1) sys.exit(1)
# Setup REST api endpoint # Setup REST api endpoint
api = RestApi('{}://{}/uds/rest/client'.format( api = RestApi(
['http', 'https'][ssl], host '{}://{}/uds/rest/client'.format(['http', 'https'][ssl], host), sslError
), sslError) )
try: try:
if platform.mac_ver()[2] == 'arm64': if platform.mac_ver()[2] == 'arm64':