Show specific error reason on setup screen connection failure

Instead of a generic "Could not reach server" for all failures, show
the actual cause: SSL cert error, timeout, or the raw connection error
message. This makes it possible to diagnose setup issues on-device
without needing a debugger.

Also extend connect timeout from 5s to 10s.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-01 14:48:49 -05:00
parent 54c2588bd6
commit abf91874c3
+15 -5
View File
@@ -37,22 +37,32 @@ class _SetupScreenState extends ConsumerState<SetupScreen> {
try {
final dio = Dio(BaseOptions(
connectTimeout: const Duration(seconds: 5),
connectTimeout: const Duration(seconds: 10),
// Accept any HTTP status — only network-level failures throw.
// A 401 or 200 both mean the server is reachable.
validateStatus: (_) => true,
));
await dio.get('$url/api/auth/status');
} on DioException catch (_) {
} on DioException catch (e) {
final msg = switch (e.type) {
DioExceptionType.badCertificate =>
'SSL certificate error. If using a self-signed cert, it must be trusted on this device.',
DioExceptionType.connectionTimeout ||
DioExceptionType.receiveTimeout =>
'Connection timed out. The server may be down or unreachable.',
DioExceptionType.connectionError =>
'Cannot connect: ${e.message ?? "network error"}',
_ => 'Error: ${e.message ?? e.type.name}',
};
setState(() {
_testing = false;
_error = 'Could not reach server. Check the URL and try again.';
_error = msg;
});
return;
} catch (_) {
} catch (e) {
setState(() {
_testing = false;
_error = 'Could not reach server. Check the URL and try again.';
_error = 'Unexpected error: $e';
});
return;
}