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:
@@ -37,22 +37,32 @@ class _SetupScreenState extends ConsumerState<SetupScreen> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
final dio = Dio(BaseOptions(
|
final dio = Dio(BaseOptions(
|
||||||
connectTimeout: const Duration(seconds: 5),
|
connectTimeout: const Duration(seconds: 10),
|
||||||
// Accept any HTTP status — only network-level failures throw.
|
// Accept any HTTP status — only network-level failures throw.
|
||||||
// A 401 or 200 both mean the server is reachable.
|
// A 401 or 200 both mean the server is reachable.
|
||||||
validateStatus: (_) => true,
|
validateStatus: (_) => true,
|
||||||
));
|
));
|
||||||
await dio.get('$url/api/auth/status');
|
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(() {
|
setState(() {
|
||||||
_testing = false;
|
_testing = false;
|
||||||
_error = 'Could not reach server. Check the URL and try again.';
|
_error = msg;
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
} catch (_) {
|
} catch (e) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_testing = false;
|
_testing = false;
|
||||||
_error = 'Could not reach server. Check the URL and try again.';
|
_error = 'Unexpected error: $e';
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user