From 02d3341b3d6ea2782c8c96e8cd76585d6dd51ad1 Mon Sep 17 00:00:00 2001 From: lemoer Date: Sun, 6 Jul 2025 01:01:05 +0200 Subject: [PATCH] Show SSH exceptions as useful error messages in SnackBars --- app/lib/main.dart | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/app/lib/main.dart b/app/lib/main.dart index 9f0ba3e..5a60a1c 100644 --- a/app/lib/main.dart +++ b/app/lib/main.dart @@ -103,8 +103,6 @@ class _MyHomePageState extends State { Future doSSH(String user) async { SSHSocket? socket; - print("Connecting to SSH server..."); - try { socket = await SSHSocket.connect( '192.168.0.15', @@ -123,11 +121,25 @@ class _MyHomePageState extends State { setState(() { _output = utf8.decode(uptime); }); - } catch (e) { - print("Error: $e"); - setState(() { - _output = "Error: $e"; - }); + } on SSHAuthError catch (_) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + "Error! Server rejected our key. Maybe you need to register it first? Or you do not have access to this lock.", + ), + duration: const Duration(seconds: 3), + ), + ); + return; + } on SocketException catch (_) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + "Error! Could not connect to SSH server. Maybe you are not in the right wifi network?", + ), + duration: const Duration(seconds: 3), + ), + ); return; } }