sync changes
This commit is contained in:
26
lib/data/interceptor/auth_interceptor.dart
Normal file
26
lib/data/interceptor/auth_interceptor.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:be_happy/presentation/viewmodel/splash_bloc.dart';
|
||||
import 'package:be_happy/presentation/event/spalsh_event.dart';
|
||||
|
||||
import '../../di/service_locator.dart';
|
||||
|
||||
class AuthInterceptor extends Interceptor {
|
||||
|
||||
AuthInterceptor();
|
||||
|
||||
@override
|
||||
void onError(DioException err, ErrorInterceptorHandler handler) {
|
||||
final String path = err.requestOptions.path;
|
||||
|
||||
if (err.response?.statusCode == 401) {
|
||||
if (!path.contains('/auth/client/refresh') && !path.contains('/auth/client/login')) {
|
||||
print('Interceptor: 401 на обычном запросе. Пытаемся обновить токен...');
|
||||
getIt<SplashBloc>().add(AuthCheckRequested());
|
||||
} else {
|
||||
print('Interceptor: 401 на запросе авторизации. Пробрасываем ошибку дальше.');
|
||||
}
|
||||
}
|
||||
|
||||
return super.onError(err, handler);
|
||||
}
|
||||
}
|
||||
@@ -667,8 +667,22 @@ class ApiService {
|
||||
|
||||
return ScooterOrder.fromJson(response.data);
|
||||
} on DioException catch (e) {
|
||||
_handleDioError(e);
|
||||
return null;
|
||||
if (e.response?.statusCode == 400) {
|
||||
final data = e.response?.data;
|
||||
|
||||
if (data is Map && data['message'] is List) {
|
||||
final firstError = data['message'][0]['message'].toString();
|
||||
|
||||
if (firstError.contains("Wrong start zone")) {
|
||||
throw WrongZoneException(message: "Некорректная зона для начала поездки.");
|
||||
}
|
||||
}
|
||||
|
||||
if (data is Map && data['message'] is String) {}
|
||||
} else {
|
||||
_handleDioError(e);
|
||||
}
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -684,8 +698,22 @@ class ApiService {
|
||||
}
|
||||
return null;
|
||||
} on DioException catch (e) {
|
||||
_handleDioError(e);
|
||||
return null;
|
||||
if (e.response?.statusCode == 400) {
|
||||
final data = e.response?.data;
|
||||
|
||||
if (data is Map && data['message'] is List) {
|
||||
final firstError = data['message'][0]['message'].toString();
|
||||
|
||||
if (firstError.contains("Wrong start zone")) {
|
||||
throw WrongZoneException(message: "Некорректная зона для начала поездки.");
|
||||
}
|
||||
}
|
||||
|
||||
if (data is Map && data['message'] is String) {}
|
||||
} else {
|
||||
_handleDioError(e);
|
||||
}
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -762,8 +790,8 @@ class ApiService {
|
||||
if (data is Map && data['message'] is List) {
|
||||
final firstError = data['message'][0]['message'].toString();
|
||||
|
||||
if (firstError.contains("Wrong zone")) {
|
||||
throw WrongZoneException(message: firstError);
|
||||
if (firstError.contains("Wrong start zone")) {
|
||||
throw WrongZoneException(message: "Некорректная зона для завершения поездки.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,32 +55,47 @@ class GeocodingRemoteDataSource {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<MasstransitRoute>?> getPedestrianRoutes(Point userPosition,
|
||||
Point targetPosition) async {
|
||||
final (session, resultFuture) = await YandexPedestrian.requestRoutes(
|
||||
points: [
|
||||
RequestPoint(
|
||||
point: userPosition, requestPointType: RequestPointType.wayPoint),
|
||||
RequestPoint(point: targetPosition,
|
||||
requestPointType: RequestPointType.wayPoint)
|
||||
],
|
||||
fitnessOptions: FitnessOptions(avoidSteep: false, avoidStairs: false),
|
||||
timeOptions: TimeOptions()
|
||||
);
|
||||
|
||||
Future<List<MasstransitRoute>?> getPedestrianRoutes(
|
||||
Point userPosition,
|
||||
Point targetPosition,
|
||||
) async {
|
||||
try {
|
||||
|
||||
print("From: ${userPosition.latitude}, ${userPosition.longitude}");
|
||||
print("To: ${targetPosition.latitude}, ${targetPosition.longitude}");
|
||||
|
||||
final (session, resultFuture) = await YandexPedestrian.requestRoutes(
|
||||
points: [
|
||||
RequestPoint(point: userPosition, requestPointType: RequestPointType.wayPoint),
|
||||
RequestPoint(point: targetPosition, requestPointType: RequestPointType.wayPoint)
|
||||
],
|
||||
fitnessOptions: const FitnessOptions(avoidSteep: false, avoidStairs: false),
|
||||
timeOptions: const TimeOptions()
|
||||
);
|
||||
|
||||
final result = await resultFuture;
|
||||
|
||||
final distance = result.routes?.first.metadata.weight.walkingDistance.value;
|
||||
if (result.routes == null || result.routes!.isEmpty) {
|
||||
print("Маршруты не найдены: список пуст или null");
|
||||
return [];
|
||||
}
|
||||
|
||||
print("Дистанция до самоката: $distance");
|
||||
final route = result.routes!.first;
|
||||
|
||||
final distance = route.metadata.weight.walkingDistance?.value;
|
||||
|
||||
if (distance != null) {
|
||||
print("Дистанция до самоката: $distance м");
|
||||
} else {
|
||||
print("Дистанция не найдена в метаданных маршрута");
|
||||
}
|
||||
|
||||
return result.routes;
|
||||
|
||||
} catch (e) {
|
||||
print('Error: $e');
|
||||
} catch (e, stack) {
|
||||
print('Pedestrian route error: $e');
|
||||
print('Stack trace: $stack');
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -164,6 +164,8 @@ class ScooterRepositoryImpl extends ScooterRepository {
|
||||
}
|
||||
} on AuthException catch (e) {
|
||||
result = Failure(AuthFailure(e.attemptsLeft));
|
||||
} on WrongZoneException catch (e) {
|
||||
result = Failure(WrongZoneFailure(e.message));
|
||||
} catch (e) {
|
||||
result = Failure(UnknownFailure("Неизвестная ошибка"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user