Fix setup screen always rejecting valid servers
Dio throws DioException for 4xx responses by default, so a server returning 401 on /api/auth/status (correct behaviour for an unauthenticated request) was caught and shown as "Could not reach server", preventing the URL from ever being saved. Set validateStatus: (_) => true so any HTTP response (200, 401, 404…) counts as "reachable". Only actual network failures (no response) now trigger the error message. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -36,16 +36,20 @@ class _SetupScreenState extends ConsumerState<SetupScreen> {
|
||||
if (url.endsWith('/')) url = url.substring(0, url.length - 1);
|
||||
|
||||
try {
|
||||
final dio = Dio(BaseOptions(connectTimeout: const Duration(seconds: 5)));
|
||||
final dio = Dio(BaseOptions(
|
||||
connectTimeout: const Duration(seconds: 5),
|
||||
// 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');
|
||||
// 401 is fine — server is reachable
|
||||
} on DioException catch (_) {
|
||||
setState(() {
|
||||
_testing = false;
|
||||
_error = 'Could not reach server. Check the URL and try again.';
|
||||
});
|
||||
return;
|
||||
} catch (e) {
|
||||
} catch (_) {
|
||||
setState(() {
|
||||
_testing = false;
|
||||
_error = 'Could not reach server. Check the URL and try again.';
|
||||
|
||||
Reference in New Issue
Block a user