fix(splash): distinguish network errors from auth errors in session check
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:sf_infrastructure/sf_infrastructure.dart';
|
||||
import 'package:sf_shared/sf_shared.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
@@ -28,6 +29,10 @@ class CheckSessionUseCaseImpl implements CheckSessionUseCase {
|
||||
try {
|
||||
await _userRepository.getUserInfo();
|
||||
} catch (e) {
|
||||
if (e is ApiException && e.isNetworkError) {
|
||||
debugPrint('[CheckSession] network error, assuming valid session: $e');
|
||||
return InitialRoute.home;
|
||||
}
|
||||
debugPrint('[CheckSession] no session: $e');
|
||||
return InitialRoute.login;
|
||||
}
|
||||
@@ -40,7 +45,7 @@ class CheckSessionUseCaseImpl implements CheckSessionUseCase {
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('[CheckSession] devices check failed: $e');
|
||||
return InitialRoute.deviceSetup;
|
||||
return InitialRoute.home;
|
||||
}
|
||||
|
||||
debugPrint('[CheckSession] → home');
|
||||
|
||||
@@ -25,11 +25,7 @@ class UserRemoteDatasourceImpl implements UserRemoteDatasource {
|
||||
final parsed = UserResponseModel.fromJson(data);
|
||||
return parsed.item;
|
||||
} on DioException catch (error) {
|
||||
final apiMsg = error.response?.data;
|
||||
final msg = apiMsg is String
|
||||
? apiMsg
|
||||
: (error.message ?? 'Error in /auth/me');
|
||||
throw Exception(msg);
|
||||
throw mapDioError(error, defaultMessage: 'Error in /auth/me');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user