forked from eatvio/eatvio_app
Compare commits
3 Commits
issue-1141
...
issue-1140
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47b81fba5a | ||
|
|
5308c11ca6 | ||
| 1e8c1ab2eb |
@@ -18,21 +18,22 @@ class AppInitializer {
|
|||||||
static Future<void> initialize({required AppBuildType buildType}) async {
|
static Future<void> initialize({required AppBuildType buildType}) async {
|
||||||
await _initializeEnvironment();
|
await _initializeEnvironment();
|
||||||
await _initializeDependencyInjection(buildType: buildType);
|
await _initializeDependencyInjection(buildType: buildType);
|
||||||
await _initializeSentry();
|
_preserveSplash();
|
||||||
await _initializeFirebase();
|
await _initializeFirebase();
|
||||||
await _initializeDebugMode();
|
await _initializeDebugMode();
|
||||||
await _initializeAnalytics();
|
await _initializeAnalytics();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Инициализация Sentry
|
static void _preserveSplash() {
|
||||||
static Future<void> _initializeSentry() async {
|
|
||||||
final widgetsBinding = SentryWidgetsFlutterBinding.ensureInitialized();
|
final widgetsBinding = SentryWidgetsFlutterBinding.ensureInitialized();
|
||||||
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
|
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Загрузка переменных окружения
|
/// Загрузка переменных окружения
|
||||||
static Future<void> _initializeEnvironment() async {
|
static Future<void> _initializeEnvironment() async {
|
||||||
await dotenv.load(fileName: ".env");
|
if (!dotenv.isInitialized) {
|
||||||
|
await dotenv.load(fileName: '.env');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Инициализация Firebase
|
/// Инициализация Firebase
|
||||||
@@ -64,20 +65,25 @@ class AppInitializer {
|
|||||||
|
|
||||||
/// Инициализация аналитики
|
/// Инициализация аналитики
|
||||||
static Future<void> _initializeAnalytics() async {
|
static Future<void> _initializeAnalytics() async {
|
||||||
AppMetrica.activate(AppMetricaConfig(EnvConfig.appMetricaApiKey));
|
AppMetrica.activate(AppMetricaConfig(EnvConfig.appMetricaApiKey, flutterCrashReporting: false));
|
||||||
AppMetrica.reportEvent('Application started');
|
AppMetrica.reportEvent('Application started');
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Запуск приложения с Sentry
|
/// Запуск приложения с Sentry
|
||||||
static Future<void> runAppWithSentry(VoidCallback appRunner) async {
|
static Future<void> runAppWithSentry(
|
||||||
|
FutureOr<void> Function() appRunner,
|
||||||
|
) async {
|
||||||
|
SentryWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
await _initializeEnvironment();
|
||||||
|
const sendInDebug = bool.fromEnvironment('SENTRY_IN_DEBUG');
|
||||||
await SentryFlutter.init((options) {
|
await SentryFlutter.init((options) {
|
||||||
options.dsn = EnvConfig.sentryDsn;
|
options.dsn = EnvConfig.sentryDsn;
|
||||||
options.tracesSampleRate = 1.0;
|
options.tracesSampleRate = 1.0;
|
||||||
options.debug = false;
|
options.debug = false;
|
||||||
|
if (kDebugMode && sendInDebug) options.environment = 'debug';
|
||||||
options.beforeSend = (event, hint) {
|
options.beforeSend = (event, hint) {
|
||||||
if (kDebugMode) return null;
|
if (kDebugMode && !sendInDebug) return null;
|
||||||
if (!ErrorReportPolicy.allowSentryEvent(event, hint)) return null;
|
return ErrorReportPolicy.prepareSentryEvent(event, hint);
|
||||||
return event;
|
|
||||||
};
|
};
|
||||||
}, appRunner: appRunner);
|
}, appRunner: appRunner);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ part 'comments_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class CommentsService {
|
abstract class CommentsService {
|
||||||
factory CommentsService(Dio dio, {String baseUrl}) = _CommentsService;
|
factory CommentsService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _CommentsService;
|
||||||
|
|
||||||
@DELETE('/api/comments/{id}')
|
@DELETE('/api/comments/{id}')
|
||||||
Future<void> deleteComment(@Path('id') int id);
|
Future<void> deleteComment(@Path('id') int id);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:eatvio_app/core/app_config.dart';
|
import 'package:eatvio_app/core/app_config.dart';
|
||||||
import 'package:eatvio_app/core/constants/app_constants.dart';
|
import 'package:eatvio_app/core/constants/app_constants.dart';
|
||||||
|
import 'package:eatvio_app/core/error_reporting/api_response_dio.dart';
|
||||||
|
import 'package:eatvio_app/core/error_reporting/api_response_error_reporter.dart';
|
||||||
import 'package:eatvio_app/core/error_reporting/error_reporter.dart';
|
import 'package:eatvio_app/core/error_reporting/error_reporter.dart';
|
||||||
import 'package:eatvio_app/core/error_reporting/sentry_error_reporter.dart';
|
import 'package:eatvio_app/core/error_reporting/sentry_error_reporter.dart';
|
||||||
import 'package:eatvio_app/core/interceptors/phone_verify_error_interceptor.dart';
|
import 'package:eatvio_app/core/interceptors/phone_verify_error_interceptor.dart';
|
||||||
@@ -18,14 +20,15 @@ class ExternalRegistrations {
|
|||||||
/// Регистрация всех внешних зависимостей
|
/// Регистрация всех внешних зависимостей
|
||||||
static void registerAll() {
|
static void registerAll() {
|
||||||
sl.registerLazySingleton<ErrorReporter>(SentryErrorReporter.new);
|
sl.registerLazySingleton<ErrorReporter>(SentryErrorReporter.new);
|
||||||
|
sl.registerLazySingleton(() => ApiResponseErrorReporter(sl()));
|
||||||
_registerDio();
|
_registerDio();
|
||||||
_registerPrefs();
|
_registerPrefs();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Регистрация Dio HTTP клиента
|
/// Регистрация Dio HTTP клиента
|
||||||
static void _registerDio() {
|
static void _registerDio() {
|
||||||
sl.registerLazySingleton(
|
sl.registerLazySingleton<Dio>(
|
||||||
() => Dio(
|
() => ApiResponseDio(
|
||||||
BaseOptions(
|
BaseOptions(
|
||||||
baseUrl: sl<AppConfig>().baseUrl,
|
baseUrl: sl<AppConfig>().baseUrl,
|
||||||
headers: {'accept': 'application/json', 'content-type': 'application/json'},
|
headers: {'accept': 'application/json', 'content-type': 'application/json'},
|
||||||
@@ -33,6 +36,7 @@ class ExternalRegistrations {
|
|||||||
receiveTimeout: AppConstants.pendingDelay,
|
receiveTimeout: AppConstants.pendingDelay,
|
||||||
sendTimeout: AppConstants.pendingDelay,
|
sendTimeout: AppConstants.pendingDelay,
|
||||||
),
|
),
|
||||||
|
sl(),
|
||||||
)..interceptors.addAll([TokenInterceptor(), PhoneVerifyErrorInterceptor()])
|
)..interceptors.addAll([TokenInterceptor(), PhoneVerifyErrorInterceptor()])
|
||||||
..addSentry(
|
..addSentry(
|
||||||
failedRequestStatusCodes: const [SentryStatusCode.defaultRange()],
|
failedRequestStatusCodes: const [SentryStatusCode.defaultRange()],
|
||||||
|
|||||||
@@ -86,7 +86,9 @@ class RepositoryRegistrations {
|
|||||||
sl.registerLazySingleton<CommentsRepository>(() => CommentsRepository(service: sl()));
|
sl.registerLazySingleton<CommentsRepository>(() => CommentsRepository(service: sl()));
|
||||||
sl.registerLazySingleton<NotificationSettingsRepository>(() => NotificationSettingsRepository(sl()));
|
sl.registerLazySingleton<NotificationSettingsRepository>(() => NotificationSettingsRepository(sl()));
|
||||||
sl.registerLazySingleton<SbpRepository>(() => SbpRepository(sbpService: sl()));
|
sl.registerLazySingleton<SbpRepository>(() => SbpRepository(sbpService: sl()));
|
||||||
sl.registerLazySingleton<PaymentRepository>(() => PaymentRepository(chatService: sl()));
|
sl.registerLazySingleton<PaymentRepository>(
|
||||||
|
() => PaymentRepository(chatService: sl(), responseErrors: sl()),
|
||||||
|
);
|
||||||
sl.registerLazySingleton<PersonalDietSuggestionRepository>(() => PersonalDietSuggestionRepository(personalDietSuggestionService: sl()));
|
sl.registerLazySingleton<PersonalDietSuggestionRepository>(() => PersonalDietSuggestionRepository(personalDietSuggestionService: sl()));
|
||||||
sl.registerLazySingleton<RegistrationRepositoryV2>(() => RegistrationRepositoryV2(registrationService: sl()));
|
sl.registerLazySingleton<RegistrationRepositoryV2>(() => RegistrationRepositoryV2(registrationService: sl()));
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:eatvio_app/core/error_reporting/api_response_error_reporter.dart';
|
||||||
import 'package:eatvio_app/core/comments/services/comments_service.dart';
|
import 'package:eatvio_app/core/comments/services/comments_service.dart';
|
||||||
import 'package:eatvio_app/core/firebase_api.dart';
|
import 'package:eatvio_app/core/firebase_api.dart';
|
||||||
import 'package:eatvio_app/core/views/service/views_service.dart';
|
import 'package:eatvio_app/core/views/service/views_service.dart';
|
||||||
@@ -56,37 +57,83 @@ class ServiceRegistrations {
|
|||||||
/// Регистрация Service как синглтонов
|
/// Регистрация Service как синглтонов
|
||||||
static void _registerSingletonServices() {
|
static void _registerSingletonServices() {
|
||||||
// Core services
|
// Core services
|
||||||
sl.registerLazySingleton<ChatService>(() => ChatService(sl()));
|
sl.registerLazySingleton<ChatService>(
|
||||||
sl.registerLazySingleton<VideoCallService>(() => VideoCallService(sl()));
|
() => ChatService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<VideoCallService>(
|
||||||
|
() => VideoCallService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
sl.registerLazySingleton<PublicDownloadsSaver>(
|
sl.registerLazySingleton<PublicDownloadsSaver>(
|
||||||
() => const PublicDownloadsSaver(),
|
() => const PublicDownloadsSaver(),
|
||||||
);
|
);
|
||||||
sl.registerLazySingleton<VideoCallRecordingFileService>(
|
sl.registerLazySingleton<VideoCallRecordingFileService>(
|
||||||
() => VideoCallRecordingFileService(dio: sl(), downloadsSaver: sl()),
|
() => VideoCallRecordingFileService(dio: sl(), downloadsSaver: sl()),
|
||||||
);
|
);
|
||||||
sl.registerLazySingleton<FeedService>(() => FeedService(sl()));
|
sl.registerLazySingleton<FeedService>(
|
||||||
sl.registerLazySingleton<ProfileService>(() => ProfileService(sl()));
|
() => FeedService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
sl.registerLazySingleton<InsightsService>(() => InsightsService(sl()));
|
);
|
||||||
sl.registerLazySingleton<CalendarService>(() => CalendarService(sl()));
|
sl.registerLazySingleton<ProfileService>(
|
||||||
sl.registerLazySingleton<SettingsService>(() => SettingsService(sl()));
|
() => ProfileService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
sl.registerLazySingleton<ConsultantService>(() => ConsultantService(sl()));
|
);
|
||||||
sl.registerLazySingleton<DiaryService>(() => DiaryService(sl()));
|
sl.registerLazySingleton<InsightsService>(
|
||||||
sl.registerLazySingleton<GlossaryService>(() => GlossaryService(sl()));
|
() => InsightsService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
sl.registerLazySingleton<BarcodeService>(() => BarcodeService(sl()));
|
);
|
||||||
sl.registerLazySingleton<DietService>(() => DietService(sl()));
|
sl.registerLazySingleton<CalendarService>(
|
||||||
sl.registerLazySingleton<PlansService>(() => PlansService(sl()));
|
() => CalendarService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
sl.registerLazySingleton<PlanService>(() => PlanService(sl()));
|
);
|
||||||
sl.registerLazySingleton<MyDietsService>(() => MyDietsService(sl()));
|
sl.registerLazySingleton<SettingsService>(
|
||||||
sl.registerLazySingleton<MyPlansService>(() => MyPlansService(sl()));
|
() => SettingsService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
sl.registerLazySingleton<WsService>(() => WsService(sl()));
|
);
|
||||||
sl.registerLazySingleton<AboutRecipeService>(() => AboutRecipeService(sl()));
|
sl.registerLazySingleton<ConsultantService>(
|
||||||
sl.registerLazySingleton<ComplainingService>(() => ComplainingService(sl()));
|
() => ConsultantService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
sl.registerLazySingleton<AuthService>(() => AuthService(sl()));
|
);
|
||||||
sl.registerLazySingleton<CardsService>(() => CardsService(sl()));
|
sl.registerLazySingleton<DiaryService>(
|
||||||
|
() => DiaryService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<GlossaryService>(
|
||||||
|
() => GlossaryService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<BarcodeService>(
|
||||||
|
() => BarcodeService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<DietService>(
|
||||||
|
() => DietService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<PlansService>(
|
||||||
|
() => PlansService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<PlanService>(
|
||||||
|
() => PlanService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<MyDietsService>(
|
||||||
|
() => MyDietsService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<MyPlansService>(
|
||||||
|
() => MyPlansService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<WsService>(() => WsService(sl(), errorLogger: sl<ApiResponseErrorReporter>()));
|
||||||
|
sl.registerLazySingleton<AboutRecipeService>(
|
||||||
|
() => AboutRecipeService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<ComplainingService>(
|
||||||
|
() => ComplainingService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<AuthService>(
|
||||||
|
() => AuthService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<CardsService>(
|
||||||
|
() => CardsService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
sl.registerLazySingleton<ConsultationService>(() => ConsultationService(sl()));
|
sl.registerLazySingleton<ConsultationService>(() => ConsultationService(sl()));
|
||||||
sl.registerLazySingleton<CancelPlanService>(() => CancelPlanService(sl()));
|
sl.registerLazySingleton<CancelPlanService>(
|
||||||
sl.registerLazySingleton<CreatePlanService>(() => CreatePlanService(sl()));
|
() => CancelPlanService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
sl.registerLazySingleton<NotificationsService>(() => NotificationsService(sl()));
|
);
|
||||||
|
sl.registerLazySingleton<CreatePlanService>(
|
||||||
|
() => CreatePlanService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<NotificationsService>(
|
||||||
|
() => NotificationsService(sl(), responseErrors: sl()),
|
||||||
|
);
|
||||||
sl.registerLazySingleton<FirebaseApi>(() => FirebaseApi(errorReporter: sl()));
|
sl.registerLazySingleton<FirebaseApi>(() => FirebaseApi(errorReporter: sl()));
|
||||||
sl.registerLazySingleton<VideoCallCallKitCoordinator>(
|
sl.registerLazySingleton<VideoCallCallKitCoordinator>(
|
||||||
() => VideoCallCallKitCoordinator(firebaseApi: sl()),
|
() => VideoCallCallKitCoordinator(firebaseApi: sl()),
|
||||||
@@ -94,23 +141,49 @@ class ServiceRegistrations {
|
|||||||
sl.registerLazySingleton<VideoCallSystemPipCoordinator>(
|
sl.registerLazySingleton<VideoCallSystemPipCoordinator>(
|
||||||
() => VideoCallSystemPipCoordinator(),
|
() => VideoCallSystemPipCoordinator(),
|
||||||
);
|
);
|
||||||
sl.registerLazySingleton<ResetPasswordService>(() => ResetPasswordService(sl()));
|
sl.registerLazySingleton<ResetPasswordService>(
|
||||||
sl.registerLazySingleton<BlockedUserService>(() => BlockedUserService(sl()));
|
() => ResetPasswordService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
sl.registerLazySingleton<CommentsService>(() => CommentsService(sl()));
|
);
|
||||||
sl.registerLazySingleton<MyRecipesService>(() => MyRecipesService(sl()));
|
sl.registerLazySingleton<BlockedUserService>(
|
||||||
sl.registerLazySingleton<ConsultantRatingService>(() => ConsultantRatingService(sl()));
|
() => BlockedUserService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
sl.registerLazySingleton<NotificationSettingsService>(() => NotificationSettingsService(sl()));
|
);
|
||||||
sl.registerLazySingleton<ViewsService>(() => ViewsService(sl()));
|
sl.registerLazySingleton<CommentsService>(
|
||||||
|
() => CommentsService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<MyRecipesService>(
|
||||||
|
() => MyRecipesService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<ConsultantRatingService>(
|
||||||
|
() => ConsultantRatingService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<NotificationSettingsService>(
|
||||||
|
() => NotificationSettingsService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<ViewsService>(
|
||||||
|
() => ViewsService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
sl.registerLazySingleton<SbpService>(() => const SbpServiceImpl());
|
sl.registerLazySingleton<SbpService>(() => const SbpServiceImpl());
|
||||||
sl.registerLazySingleton<PersonalDietSuggestionService>(() => PersonalDietSuggestionService(sl()));
|
sl.registerLazySingleton<PersonalDietSuggestionService>(
|
||||||
sl.registerLazySingleton<RegistrationServiceV2>(() => RegistrationServiceV2(sl()));
|
() => PersonalDietSuggestionService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<RegistrationServiceV2>(
|
||||||
|
() => RegistrationServiceV2(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
|
||||||
// Content services
|
// Content services
|
||||||
sl.registerLazySingleton<CreateRecipeService>(() => CreateRecipeService(sl()));
|
sl.registerLazySingleton<CreateRecipeService>(
|
||||||
sl.registerLazySingleton<BlogPostService>(() => BlogPostService(sl()));
|
() => CreateRecipeService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
sl.registerLazySingleton<CreateDietService>(() => CreateDietService(sl()));
|
);
|
||||||
|
sl.registerLazySingleton<BlogPostService>(
|
||||||
|
() => BlogPostService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
sl.registerLazySingleton<CreateDietService>(
|
||||||
|
() => CreateDietService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
|
|
||||||
// Auth services
|
// Auth services
|
||||||
sl.registerLazySingleton<RegistrationService>(() => RegistrationService(sl()));
|
sl.registerLazySingleton<RegistrationService>(
|
||||||
|
() => RegistrationService(sl(), errorLogger: sl<ApiResponseErrorReporter>()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
71
lib/core/error_reporting/api_response_dio.dart
Normal file
71
lib/core/error_reporting/api_response_dio.dart
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:dio/io.dart';
|
||||||
|
import 'package:eatvio_app/core/error_reporting/api_response_error_reporter.dart';
|
||||||
|
|
||||||
|
class ApiResponseDio extends DioForNative {
|
||||||
|
ApiResponseDio(BaseOptions super.options, this._responseErrors) {
|
||||||
|
transformer = _ApiResponseTransformer(
|
||||||
|
transformer,
|
||||||
|
_responseErrors,
|
||||||
|
_responseStatuses,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final ApiResponseErrorReporter _responseErrors;
|
||||||
|
final _responseStatuses = Expando<int>();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Response<T>> fetch<T>(RequestOptions requestOptions) async {
|
||||||
|
try {
|
||||||
|
return await super.fetch<T>(requestOptions);
|
||||||
|
} on DioException catch (error) {
|
||||||
|
final cause = error.error;
|
||||||
|
final status = _responseStatuses[error.requestOptions];
|
||||||
|
// Dio приводит тип корневого значения до вызова fromJson в Retrofit.
|
||||||
|
if (error.type == DioExceptionType.unknown &&
|
||||||
|
error.requestOptions.responseType == ResponseType.json &&
|
||||||
|
cause is TypeError &&
|
||||||
|
status != null) {
|
||||||
|
_responseErrors.report(
|
||||||
|
error,
|
||||||
|
cause.stackTrace ?? error.stackTrace,
|
||||||
|
method: error.requestOptions.method,
|
||||||
|
statusCode: status,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ApiResponseTransformer implements Transformer {
|
||||||
|
_ApiResponseTransformer(this._delegate, this._responseErrors, this._statuses);
|
||||||
|
|
||||||
|
final Transformer _delegate;
|
||||||
|
final ApiResponseErrorReporter _responseErrors;
|
||||||
|
final Expando<int> _statuses;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<String> transformRequest(RequestOptions options) =>
|
||||||
|
_delegate.transformRequest(options);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<dynamic> transformResponse(
|
||||||
|
RequestOptions options,
|
||||||
|
ResponseBody response,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
final data = await _delegate.transformResponse(options, response);
|
||||||
|
_statuses[options] = response.statusCode;
|
||||||
|
return data;
|
||||||
|
} on FormatException catch (error, stackTrace) {
|
||||||
|
_responseErrors.report(
|
||||||
|
error,
|
||||||
|
stackTrace,
|
||||||
|
method: options.method,
|
||||||
|
statusCode: response.statusCode,
|
||||||
|
);
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
111
lib/core/error_reporting/api_response_error_reporter.dart
Normal file
111
lib/core/error_reporting/api_response_error_reporter.dart
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:eatvio_app/core/error_reporting/error_reporter.dart';
|
||||||
|
import 'package:retrofit/retrofit.dart';
|
||||||
|
|
||||||
|
class ApiResponseErrorReporter implements ParseErrorLogger {
|
||||||
|
ApiResponseErrorReporter(this._reporter);
|
||||||
|
|
||||||
|
final ErrorReporter _reporter;
|
||||||
|
static final _capturedErrors = Expando<bool>();
|
||||||
|
|
||||||
|
static bool wasCaptured(Object error) =>
|
||||||
|
_isCaptured(error) || (error is DioException && _isCaptured(error.error));
|
||||||
|
|
||||||
|
static bool _isCaptured(Object? error) =>
|
||||||
|
error != null &&
|
||||||
|
(error is Error || error is Exception) &&
|
||||||
|
_capturedErrors[error] == true;
|
||||||
|
|
||||||
|
static T decode<T>(
|
||||||
|
ApiResponseErrorReporter? reporter,
|
||||||
|
Response<dynamic> response,
|
||||||
|
String endpoint,
|
||||||
|
T Function() parse,
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
return parse();
|
||||||
|
} catch (error, stackTrace) {
|
||||||
|
reporter?.report(
|
||||||
|
error,
|
||||||
|
stackTrace,
|
||||||
|
method: response.requestOptions.method,
|
||||||
|
statusCode: response.statusCode,
|
||||||
|
endpoint: endpoint,
|
||||||
|
);
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void logError(
|
||||||
|
Object error,
|
||||||
|
StackTrace stackTrace,
|
||||||
|
RequestOptions options, {
|
||||||
|
Response<dynamic>? response,
|
||||||
|
}) {
|
||||||
|
report(
|
||||||
|
error,
|
||||||
|
stackTrace,
|
||||||
|
method: options.method,
|
||||||
|
statusCode: response?.statusCode,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void report(
|
||||||
|
Object error,
|
||||||
|
StackTrace stackTrace, {
|
||||||
|
required String method,
|
||||||
|
int? statusCode,
|
||||||
|
String? endpoint,
|
||||||
|
}) {
|
||||||
|
if (error is Error || error is Exception) {
|
||||||
|
_capturedErrors[error] = true;
|
||||||
|
}
|
||||||
|
// Сообщение исходного исключения может содержать значения из ответа API.
|
||||||
|
final cause = error is DioException ? error.error ?? error : error;
|
||||||
|
unawaited(
|
||||||
|
_send(
|
||||||
|
ApiResponseDecodeException(cause.runtimeType.toString()),
|
||||||
|
stackTrace,
|
||||||
|
{
|
||||||
|
'http_method': method,
|
||||||
|
'http_status_code': ?statusCode,
|
||||||
|
'endpoint': ?endpoint,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _send(
|
||||||
|
ApiResponseDecodeException error,
|
||||||
|
StackTrace stackTrace,
|
||||||
|
Map<String, Object?> context,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
await _reporter.report(
|
||||||
|
error,
|
||||||
|
stackTrace,
|
||||||
|
origin: 'api_response',
|
||||||
|
extras: context,
|
||||||
|
);
|
||||||
|
} catch (reportError, reportStackTrace) {
|
||||||
|
log(
|
||||||
|
'Не удалось записать ошибку разбора ответа API',
|
||||||
|
error: reportError.runtimeType,
|
||||||
|
stackTrace: reportStackTrace,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ApiResponseDecodeException implements Exception {
|
||||||
|
ApiResponseDecodeException(this.causeType);
|
||||||
|
|
||||||
|
final String causeType;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() => 'Could not decode API response ($causeType)';
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:eatvio_app/core/error_reporting/api_response_error_reporter.dart';
|
||||||
import 'package:eatvio_app/core/push/hms_client_error.dart';
|
import 'package:eatvio_app/core/push/hms_client_error.dart';
|
||||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||||
|
|
||||||
@@ -14,6 +15,7 @@ class ErrorReportPolicy {
|
|||||||
/// When `false`, the error is not sent via [ErrorReporter].
|
/// When `false`, the error is not sent via [ErrorReporter].
|
||||||
static bool shouldReport(Object? error) {
|
static bool shouldReport(Object? error) {
|
||||||
if (error == null) return false;
|
if (error == null) return false;
|
||||||
|
if (ApiResponseErrorReporter.wasCaptured(error)) return false;
|
||||||
if (error is String) return false;
|
if (error is String) return false;
|
||||||
if (error is SocketException) return false;
|
if (error is SocketException) return false;
|
||||||
if (isHmsClientUnavailable(error)) return false;
|
if (isHmsClientUnavailable(error)) return false;
|
||||||
@@ -34,11 +36,23 @@ class ErrorReportPolicy {
|
|||||||
final t = event.throwable;
|
final t = event.throwable;
|
||||||
if (t == null) return true;
|
if (t == null) return true;
|
||||||
if (t is DioException) {
|
if (t is DioException) {
|
||||||
return _allowSentrySdkDio(t);
|
return !ApiResponseErrorReporter.wasCaptured(t) && _allowSentrySdkDio(t);
|
||||||
}
|
}
|
||||||
return shouldReport(t);
|
return shouldReport(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SentryEvent? prepareSentryEvent(SentryEvent event, Hint hint) {
|
||||||
|
if (!allowSentryEvent(event, hint)) return null;
|
||||||
|
if (event.throwable is ApiResponseDecodeException) {
|
||||||
|
// HTTP breadcrumbs могут содержать идентификаторы в пути и параметры запроса.
|
||||||
|
event.breadcrumbs = event.breadcrumbs
|
||||||
|
?.where((breadcrumb) => breadcrumb.category != 'http')
|
||||||
|
.toList();
|
||||||
|
event.request = null;
|
||||||
|
}
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
/// Cancel, timeouts, socket / connection errors — do not send (noisy, often user environment).
|
/// Cancel, timeouts, socket / connection errors — do not send (noisy, often user environment).
|
||||||
static bool _isTransientDioFailure(DioException e) {
|
static bool _isTransientDioFailure(DioException e) {
|
||||||
switch (e.type) {
|
switch (e.type) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:eatvio_app/core/app_config.dart';
|
import 'package:eatvio_app/core/app_config.dart';
|
||||||
|
import 'package:eatvio_app/core/error_reporting/api_response_error_reporter.dart';
|
||||||
import 'package:eatvio_app/core/firebase_api.dart';
|
import 'package:eatvio_app/core/firebase_api.dart';
|
||||||
import 'package:eatvio_app/core/locator_service.dart';
|
import 'package:eatvio_app/core/locator_service.dart';
|
||||||
import 'package:eatvio_app/core/prefs.dart';
|
import 'package:eatvio_app/core/prefs.dart';
|
||||||
@@ -103,7 +104,7 @@ class OtherRoutes {
|
|||||||
redirect: (context, state) async {
|
redirect: (context, state) async {
|
||||||
try {
|
try {
|
||||||
// Проверка версии с таймаутом, чтобы не блокировать запуск приложения
|
// Проверка версии с таймаутом, чтобы не блокировать запуск приложения
|
||||||
final versions = await sl<Dio>()
|
final response = await sl<Dio>()
|
||||||
.get('${sl<AppConfig>().baseUrl}/api/app_versions')
|
.get('${sl<AppConfig>().baseUrl}/api/app_versions')
|
||||||
.timeout(
|
.timeout(
|
||||||
const Duration(seconds: 5),
|
const Duration(seconds: 5),
|
||||||
@@ -111,12 +112,8 @@ class OtherRoutes {
|
|||||||
// При таймауте пропускаем проверку и идем дальше
|
// При таймауте пропускаем проверку и идем дальше
|
||||||
throw TimeoutException('Version check timeout');
|
throw TimeoutException('Version check timeout');
|
||||||
},
|
},
|
||||||
)
|
);
|
||||||
.then((response) => response.data)
|
final versions = response.data;
|
||||||
.catchError((e) {
|
|
||||||
// При любой ошибке пропускаем проверку версии
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (versions == null) {
|
if (versions == null) {
|
||||||
// Если проверка не удалась, пропускаем экран обновления
|
// Если проверка не удалась, пропускаем экран обновления
|
||||||
@@ -126,7 +123,15 @@ class OtherRoutes {
|
|||||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||||
String version = packageInfo.version;
|
String version = packageInfo.version;
|
||||||
Version currentVersion = Version.parse(version);
|
Version currentVersion = Version.parse(version);
|
||||||
Version latestVersion = Version.parse(versions['min_version']);
|
final responseErrors = sl.isRegistered<ApiResponseErrorReporter>()
|
||||||
|
? sl<ApiResponseErrorReporter>()
|
||||||
|
: null;
|
||||||
|
final latestVersion = ApiResponseErrorReporter.decode(
|
||||||
|
responseErrors,
|
||||||
|
response,
|
||||||
|
'/api/app_versions',
|
||||||
|
() => Version.parse(versions['min_version']),
|
||||||
|
);
|
||||||
if (latestVersion > currentVersion) {
|
if (latestVersion > currentVersion) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ part 'views_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class ViewsService {
|
abstract class ViewsService {
|
||||||
factory ViewsService(Dio dio, {String baseUrl}) = _ViewsService;
|
factory ViewsService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _ViewsService;
|
||||||
|
|
||||||
@POST('/api/views')
|
@POST('/api/views')
|
||||||
Future<void> viewContent({
|
Future<void> viewContent({
|
||||||
|
|||||||
@@ -8,7 +8,11 @@ part 'ws_service.g.dart';
|
|||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class WsService {
|
abstract class WsService {
|
||||||
|
|
||||||
factory WsService(Dio dio, {String baseUrl}) = _WsService;
|
factory WsService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _WsService;
|
||||||
|
|
||||||
@GET('/api/profile/ws/params')
|
@GET('/api/profile/ws/params')
|
||||||
Future<WebsocketInfoModel> getWebsocket();
|
Future<WebsocketInfoModel> getWebsocket();
|
||||||
|
|||||||
@@ -12,7 +12,11 @@ part 'auth_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class AuthService {
|
abstract class AuthService {
|
||||||
factory AuthService(Dio dio, {String? baseUrl}) = _AuthService;
|
factory AuthService(
|
||||||
|
Dio dio, {
|
||||||
|
String? baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _AuthService;
|
||||||
|
|
||||||
@POST('/api/login')
|
@POST('/api/login')
|
||||||
Future<TokenModel> getTokenByCredentials({@Body() required CredentialsModel credentials});
|
Future<TokenModel> getTokenByCredentials({@Body() required CredentialsModel credentials});
|
||||||
|
|||||||
@@ -5,7 +5,11 @@ part 'reset_password_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class ResetPasswordService {
|
abstract class ResetPasswordService {
|
||||||
factory ResetPasswordService(Dio dio, {String baseUrl}) = _ResetPasswordService;
|
factory ResetPasswordService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _ResetPasswordService;
|
||||||
|
|
||||||
@POST('/api/send_password_reset_code')
|
@POST('/api/send_password_reset_code')
|
||||||
Future<HttpResponse> sendEmailCodeForPasswordChange({
|
Future<HttpResponse> sendEmailCodeForPasswordChange({
|
||||||
|
|||||||
@@ -1,24 +1,28 @@
|
|||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:eatvio_app/features/barcode/models/barcode_product_model.dart';
|
import 'package:eatvio_app/features/barcode/models/barcode_product_model.dart';
|
||||||
import 'package:retrofit/retrofit.dart';
|
import 'package:retrofit/retrofit.dart';
|
||||||
|
|
||||||
part 'barcode_service.g.dart';
|
part 'barcode_service.g.dart';
|
||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class BarcodeService {
|
abstract class BarcodeService {
|
||||||
factory BarcodeService(Dio dio, {String baseUrl}) = _BarcodeService;
|
factory BarcodeService(
|
||||||
|
Dio dio, {
|
||||||
@GET('/api/gsone/barcode/{barcode}')
|
String baseUrl,
|
||||||
Future<BarcodeProductModel> getProductByBarcode({@Path('barcode') required String barcode});
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _BarcodeService;
|
||||||
@GET('/api/gsone/barcode/status/{task_id}')
|
|
||||||
Future<BarcodeTaskStatusModel> getTaskStatus({@Path('task_id') required String taskId});
|
@GET('/api/gsone/barcode/{barcode}')
|
||||||
}
|
Future<BarcodeProductModel> getProductByBarcode({@Path('barcode') required String barcode});
|
||||||
|
|
||||||
|
@GET('/api/gsone/barcode/status/{task_id}')
|
||||||
|
Future<BarcodeTaskStatusModel> getTaskStatus({@Path('task_id') required String taskId});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,11 @@ part 'blog_post_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class BlogPostService {
|
abstract class BlogPostService {
|
||||||
factory BlogPostService(Dio dio, {String baseUrl}) = _BlogPostService;
|
factory BlogPostService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _BlogPostService;
|
||||||
|
|
||||||
@POST('/api/v2/blogPosts/create/published')
|
@POST('/api/v2/blogPosts/create/published')
|
||||||
@MultiPart()
|
@MultiPart()
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ part 'calendar_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class CalendarService {
|
abstract class CalendarService {
|
||||||
factory CalendarService(Dio dio, {String baseUrl}) = _CalendarService;
|
factory CalendarService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _CalendarService;
|
||||||
|
|
||||||
@GET('/api/calendar/index')
|
@GET('/api/calendar/index')
|
||||||
Future<List<CalendarModel>> getCalendar();
|
Future<List<CalendarModel>> getCalendar();
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ part 'cancel_plan_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class CancelPlanService {
|
abstract class CancelPlanService {
|
||||||
factory CancelPlanService(Dio dio, {String baseUrl}) = _CancelPlanService;
|
factory CancelPlanService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _CancelPlanService;
|
||||||
|
|
||||||
@POST('/api/chosen_plans/{id}/cancel')
|
@POST('/api/chosen_plans/{id}/cancel')
|
||||||
Future<void> cancelChosenPlan({
|
Future<void> cancelChosenPlan({
|
||||||
|
|||||||
@@ -17,7 +17,11 @@ part 'chat_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class ChatService {
|
abstract class ChatService {
|
||||||
factory ChatService(Dio dio, {String baseUrl}) = _ChatService;
|
factory ChatService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _ChatService;
|
||||||
|
|
||||||
@GET('/api/v2/chat/index')
|
@GET('/api/v2/chat/index')
|
||||||
Future<ChatRoomPaginationModel> getChatRooms({
|
Future<ChatRoomPaginationModel> getChatRooms({
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ part 'complaining_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class ComplainingService {
|
abstract class ComplainingService {
|
||||||
factory ComplainingService(Dio dio, {String baseUrl}) = _ComplainingService;
|
factory ComplainingService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _ComplainingService;
|
||||||
|
|
||||||
@POST('/api/plans/{slug}/complain/{category}')
|
@POST('/api/plans/{slug}/complain/{category}')
|
||||||
Future<void> sendPlanComplain({
|
Future<void> sendPlanComplain({
|
||||||
|
|||||||
@@ -9,7 +9,11 @@ part 'consultant_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class ConsultantService {
|
abstract class ConsultantService {
|
||||||
factory ConsultantService(Dio dio, {String baseUrl}) = _ConsultantService;
|
factory ConsultantService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _ConsultantService;
|
||||||
|
|
||||||
@POST('/api/v2/consultant_request/registration')
|
@POST('/api/v2/consultant_request/registration')
|
||||||
Future<void> consultantRegistration({
|
Future<void> consultantRegistration({
|
||||||
|
|||||||
@@ -8,7 +8,11 @@ part 'consultant_rating_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class ConsultantRatingService {
|
abstract class ConsultantRatingService {
|
||||||
factory ConsultantRatingService(Dio dio, {String baseUrl}) = _ConsultantRatingService;
|
factory ConsultantRatingService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _ConsultantRatingService;
|
||||||
|
|
||||||
@GET('/api/consultants/rating/statistics')
|
@GET('/api/consultants/rating/statistics')
|
||||||
Future<StatisticsModel> getConsultantStatistics({@Query('filters[duration][\$gte]') String? date});
|
Future<StatisticsModel> getConsultantStatistics({@Query('filters[duration][\$gte]') String? date});
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ part 'create_diet_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class CreateDietService {
|
abstract class CreateDietService {
|
||||||
factory CreateDietService(Dio dio, {String baseUrl}) = _CreateDietService;
|
factory CreateDietService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _CreateDietService;
|
||||||
|
|
||||||
@POST('/api/diets/create/published')
|
@POST('/api/diets/create/published')
|
||||||
@MultiPart()
|
@MultiPart()
|
||||||
|
|||||||
@@ -5,7 +5,11 @@ part 'create_plan_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class CreatePlanService {
|
abstract class CreatePlanService {
|
||||||
factory CreatePlanService(Dio dio, {String baseUrl}) = _CreatePlanService;
|
factory CreatePlanService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _CreatePlanService;
|
||||||
|
|
||||||
@POST('/api/plans/create/published')
|
@POST('/api/plans/create/published')
|
||||||
@MultiPart()
|
@MultiPart()
|
||||||
|
|||||||
@@ -8,7 +8,11 @@ part 'recipe_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class CreateRecipeService {
|
abstract class CreateRecipeService {
|
||||||
factory CreateRecipeService(Dio dio, {String baseUrl}) = _CreateRecipeService;
|
factory CreateRecipeService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _CreateRecipeService;
|
||||||
|
|
||||||
@POST('/api/recipes/{slug}/like')
|
@POST('/api/recipes/{slug}/like')
|
||||||
Future<void> likeRecipe({
|
Future<void> likeRecipe({
|
||||||
|
|||||||
@@ -13,7 +13,11 @@ part 'diary_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class DiaryService {
|
abstract class DiaryService {
|
||||||
factory DiaryService(Dio dio, {String baseUrl}) = _DiaryService;
|
factory DiaryService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _DiaryService;
|
||||||
|
|
||||||
@GET('/api/diary/index/{date}')
|
@GET('/api/diary/index/{date}')
|
||||||
Future<List<DiaryDayModel>> getDiaryIndexByDate({@Path('date') required String date});
|
Future<List<DiaryDayModel>> getDiaryIndexByDate({@Path('date') required String date});
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ part 'diet_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class DietService {
|
abstract class DietService {
|
||||||
factory DietService(Dio dio, {String baseUrl}) = _DietService;
|
factory DietService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _DietService;
|
||||||
|
|
||||||
@POST('/api/diets/{id}/like')
|
@POST('/api/diets/{id}/like')
|
||||||
Future<DietLikesModel> likeDiet({
|
Future<DietLikesModel> likeDiet({
|
||||||
|
|||||||
@@ -14,7 +14,11 @@ part 'feed_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class FeedService {
|
abstract class FeedService {
|
||||||
factory FeedService(Dio dio, {String baseUrl}) = _FeedService;
|
factory FeedService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _FeedService;
|
||||||
|
|
||||||
@GET('/api/blogPosts/index')
|
@GET('/api/blogPosts/index')
|
||||||
Future<FeedBlogPostSettingsModel> getBlogPostList({@Query('page') required int page, @Query('query_search') String? query});
|
Future<FeedBlogPostSettingsModel> getBlogPostList({@Query('page') required int page, @Query('query_search') String? query});
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ part 'glossary_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class GlossaryService {
|
abstract class GlossaryService {
|
||||||
factory GlossaryService(Dio dio, {String baseUrl}) = _GlossaryService;
|
factory GlossaryService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _GlossaryService;
|
||||||
|
|
||||||
@GET('/api/glossaries/search')
|
@GET('/api/glossaries/search')
|
||||||
Future<GlossaryPaginationModel> getGlossaryByQuery({
|
Future<GlossaryPaginationModel> getGlossaryByQuery({
|
||||||
|
|||||||
@@ -9,7 +9,11 @@ part 'insights_service.g.dart';
|
|||||||
/// недоступный профиль — 403.
|
/// недоступный профиль — 403.
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class InsightsService {
|
abstract class InsightsService {
|
||||||
factory InsightsService(Dio dio, {String baseUrl}) = _InsightsService;
|
factory InsightsService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _InsightsService;
|
||||||
|
|
||||||
/// Свои графики целиком.
|
/// Свои графики целиком.
|
||||||
@GET('/api/profile/insights')
|
@GET('/api/profile/insights')
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ part 'blocked_users_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class BlockedUserService {
|
abstract class BlockedUserService {
|
||||||
factory BlockedUserService(Dio dio, {String baseUrl}) = _BlockedUserService;
|
factory BlockedUserService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _BlockedUserService;
|
||||||
|
|
||||||
@GET('/api/blocked_users')
|
@GET('/api/blocked_users')
|
||||||
Future<BlockedUsersModel> getBlockedUsers();
|
Future<BlockedUsersModel> getBlockedUsers();
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ part 'notification_settings_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class NotificationSettingsService {
|
abstract class NotificationSettingsService {
|
||||||
factory NotificationSettingsService(Dio dio, {String baseUrl}) = _NotificationSettingsService;
|
factory NotificationSettingsService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _NotificationSettingsService;
|
||||||
|
|
||||||
@GET('/api/profile/notification_settings')
|
@GET('/api/profile/notification_settings')
|
||||||
Future<NotificationSettingsModel> getNotificationSettings();
|
Future<NotificationSettingsModel> getNotificationSettings();
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ part 'my_diets_service.g.dart';
|
|||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class MyDietsService {
|
abstract class MyDietsService {
|
||||||
|
|
||||||
factory MyDietsService(Dio dio, {String baseUrl}) = _MyDietsService;
|
factory MyDietsService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _MyDietsService;
|
||||||
|
|
||||||
@GET('/api/profile/my_diets')
|
@GET('/api/profile/my_diets')
|
||||||
Future<DietsPagination> getDiets({
|
Future<DietsPagination> getDiets({
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ part 'cards_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class CardsService {
|
abstract class CardsService {
|
||||||
factory CardsService(Dio dio, {String baseUrl}) = _CardsService;
|
factory CardsService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _CardsService;
|
||||||
|
|
||||||
@GET('/api/finances/cards')
|
@GET('/api/finances/cards')
|
||||||
Future<List<CardModel>> getCards();
|
Future<List<CardModel>> getCards();
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ part 'my_plans_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class MyPlansService {
|
abstract class MyPlansService {
|
||||||
factory MyPlansService(Dio dio, {String baseUrl}) = _MyPlansService;
|
factory MyPlansService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _MyPlansService;
|
||||||
|
|
||||||
@GET('/api/profile/my_plans')
|
@GET('/api/profile/my_plans')
|
||||||
Future<PlanPaginationModel> getPlans({
|
Future<PlanPaginationModel> getPlans({
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:eatvio_app/core/error_reporting/api_response_error_reporter.dart';
|
||||||
import 'package:eatvio_app/features/notifications/models/notification_model.dart';
|
import 'package:eatvio_app/features/notifications/models/notification_model.dart';
|
||||||
|
|
||||||
class NotificationsService {
|
class NotificationsService {
|
||||||
final Dio dio;
|
final Dio dio;
|
||||||
NotificationsService(this.dio);
|
final ApiResponseErrorReporter? responseErrors;
|
||||||
|
static const _endpoint = '/api/profile/notifications';
|
||||||
|
|
||||||
|
NotificationsService(this.dio, {this.responseErrors});
|
||||||
|
|
||||||
Future<Map<String, dynamic>?> getNotifications({required int page}) async {
|
Future<Map<String, dynamic>?> getNotifications({required int page}) async {
|
||||||
|
final response = await dio.get('$_endpoint?page=$page');
|
||||||
try {
|
try {
|
||||||
final response = await dio.get('/api/profile/notifications?page=$page');
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = response.data['data'] as List<dynamic>;
|
final data = response.data['data'] as List<dynamic>;
|
||||||
|
|
||||||
@@ -493,7 +497,14 @@ class NotificationsService {
|
|||||||
),
|
),
|
||||||
NotificationType.unknown => UnknownNotification(type: type, createdAt: parseDate(createdAt)),
|
NotificationType.unknown => UnknownNotification(type: type, createdAt: parseDate(createdAt)),
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (error, stackTrace) {
|
||||||
|
responseErrors?.report(
|
||||||
|
error,
|
||||||
|
stackTrace,
|
||||||
|
method: response.requestOptions.method,
|
||||||
|
statusCode: response.statusCode,
|
||||||
|
endpoint: _endpoint,
|
||||||
|
);
|
||||||
return UnknownNotification(type: NotificationType.unknown, createdAt: DateTime.now());
|
return UnknownNotification(type: NotificationType.unknown, createdAt: DateTime.now());
|
||||||
}
|
}
|
||||||
}).toList();
|
}).toList();
|
||||||
@@ -510,7 +521,14 @@ class NotificationsService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (e) {
|
} catch (error, stackTrace) {
|
||||||
|
responseErrors?.report(
|
||||||
|
error,
|
||||||
|
stackTrace,
|
||||||
|
method: response.requestOptions.method,
|
||||||
|
statusCode: response.statusCode,
|
||||||
|
endpoint: _endpoint,
|
||||||
|
);
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:eatvio_app/core/error_reporting/api_response_error_reporter.dart';
|
||||||
import 'package:eatvio_app/features/chat/models/payment_model.dart';
|
import 'package:eatvio_app/features/chat/models/payment_model.dart';
|
||||||
import 'package:eatvio_app/features/chat/services/chat_service.dart';
|
import 'package:eatvio_app/features/chat/services/chat_service.dart';
|
||||||
import 'package:eatvio_app/features/payment/models/promo_applied_list_response.dart';
|
import 'package:eatvio_app/features/payment/models/promo_applied_list_response.dart';
|
||||||
@@ -10,8 +11,9 @@ import 'package:eatvio_app/features/payment/models/promo_validate_response.dart'
|
|||||||
/// Репозиторий оплаты консультаций (chosen_plan) через Alfa Bank / СБП.
|
/// Репозиторий оплаты консультаций (chosen_plan) через Alfa Bank / СБП.
|
||||||
class PaymentRepository {
|
class PaymentRepository {
|
||||||
final ChatService chatService;
|
final ChatService chatService;
|
||||||
|
final ApiResponseErrorReporter? responseErrors;
|
||||||
|
|
||||||
PaymentRepository({required this.chatService});
|
PaymentRepository({required this.chatService, this.responseErrors});
|
||||||
|
|
||||||
/// Запускает процесс оплаты: POST `/api/chosen_plans/{id}/start_payment_process`
|
/// Запускает процесс оплаты: POST `/api/chosen_plans/{id}/start_payment_process`
|
||||||
/// с `payment_provider: alfa-bank`.
|
/// с `payment_provider: alfa-bank`.
|
||||||
@@ -64,9 +66,15 @@ class PaymentRepository {
|
|||||||
body: {'promo_code': promoCode},
|
body: {'promo_code': promoCode},
|
||||||
);
|
);
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final data = e.response?.data;
|
final response = e.response;
|
||||||
if (data is Map<String, dynamic>) {
|
final data = response?.data;
|
||||||
return PromoApplyResponse.fromJson(data);
|
if (response != null && data is Map<String, dynamic>) {
|
||||||
|
return ApiResponseErrorReporter.decode(
|
||||||
|
responseErrors,
|
||||||
|
response,
|
||||||
|
'/api/chosen_plans/{id}/apply_promo',
|
||||||
|
() => PromoApplyResponse.fromJson(data),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
@@ -77,9 +85,15 @@ class PaymentRepository {
|
|||||||
try {
|
try {
|
||||||
return await chatService.removePromoCode(id: planId);
|
return await chatService.removePromoCode(id: planId);
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final data = e.response?.data;
|
final response = e.response;
|
||||||
if (data is Map<String, dynamic>) {
|
final data = response?.data;
|
||||||
return PromoRemoveResponse.fromJson(data);
|
if (response != null && data is Map<String, dynamic>) {
|
||||||
|
return ApiResponseErrorReporter.decode(
|
||||||
|
responseErrors,
|
||||||
|
response,
|
||||||
|
'/api/chosen_plans/{id}/remove_promo_code',
|
||||||
|
() => PromoRemoveResponse.fromJson(data),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,11 @@ part 'personal_diet_suggestion_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class PersonalDietSuggestionService {
|
abstract class PersonalDietSuggestionService {
|
||||||
factory PersonalDietSuggestionService(Dio dio, {String? baseUrl}) =
|
factory PersonalDietSuggestionService(
|
||||||
_PersonalDietSuggestionService;
|
Dio dio, {
|
||||||
|
String? baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _PersonalDietSuggestionService;
|
||||||
|
|
||||||
@GET('/api/consultations')
|
@GET('/api/consultations')
|
||||||
Future<ConsultationPaginationModel> getConsultationWithPersonalDiets({
|
Future<ConsultationPaginationModel> getConsultationWithPersonalDiets({
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ part 'plan_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class PlanService {
|
abstract class PlanService {
|
||||||
factory PlanService(Dio dio, {String baseUrl}) = _PlanService;
|
factory PlanService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _PlanService;
|
||||||
|
|
||||||
@GET('/api/plans/show/{slug}')
|
@GET('/api/plans/show/{slug}')
|
||||||
Future<PlanModel> getPlan(@Path('slug') String slug);
|
Future<PlanModel> getPlan(@Path('slug') String slug);
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ part 'plans_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class PlansService {
|
abstract class PlansService {
|
||||||
factory PlansService(Dio dio, {String baseUrl}) = _PlansService;
|
factory PlansService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _PlansService;
|
||||||
|
|
||||||
@GET('/api/plans/get_by_author/{author}')
|
@GET('/api/plans/get_by_author/{author}')
|
||||||
Future<PlanPaginationModel> getPlansBySlug({
|
Future<PlanPaginationModel> getPlansBySlug({
|
||||||
|
|||||||
@@ -14,7 +14,11 @@ part 'profile_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class ProfileService {
|
abstract class ProfileService {
|
||||||
factory ProfileService(Dio dio, {String baseUrl}) = _ProfileService;
|
factory ProfileService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _ProfileService;
|
||||||
|
|
||||||
@GET('/api/profile/show/{slug}')
|
@GET('/api/profile/show/{slug}')
|
||||||
Future<ProfileModel> getProfileBySlug({@Path() required String slug});
|
Future<ProfileModel> getProfileBySlug({@Path() required String slug});
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ part 'about_recipe_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class AboutRecipeService {
|
abstract class AboutRecipeService {
|
||||||
factory AboutRecipeService(Dio dio, {String baseUrl}) = _AboutRecipeService;
|
factory AboutRecipeService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _AboutRecipeService;
|
||||||
|
|
||||||
@POST('/api/recipes/{slug}/like')
|
@POST('/api/recipes/{slug}/like')
|
||||||
Future<void> likeRecipe({
|
Future<void> likeRecipe({
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ part 'my_recipes_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class MyRecipesService {
|
abstract class MyRecipesService {
|
||||||
factory MyRecipesService(Dio dio, {String baseUrl}) = _MyRecipesService;
|
factory MyRecipesService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _MyRecipesService;
|
||||||
|
|
||||||
@GET('/api/recipes/my')
|
@GET('/api/recipes/my')
|
||||||
Future<MyRecipePaginationModel> getMyRecipes();
|
Future<MyRecipePaginationModel> getMyRecipes();
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ part 'registration_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class RegistrationService {
|
abstract class RegistrationService {
|
||||||
factory RegistrationService(Dio dio, {String baseUrl}) = _RegistrationService;
|
factory RegistrationService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _RegistrationService;
|
||||||
|
|
||||||
@POST('/api/register')
|
@POST('/api/register')
|
||||||
Future<Map<String, String>> register({
|
Future<Map<String, String>> register({
|
||||||
|
|||||||
@@ -5,7 +5,11 @@ part 'registration_service_v2.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class RegistrationServiceV2 {
|
abstract class RegistrationServiceV2 {
|
||||||
factory RegistrationServiceV2(Dio dio, {String baseUrl}) = _RegistrationServiceV2;
|
factory RegistrationServiceV2(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _RegistrationServiceV2;
|
||||||
|
|
||||||
@POST('/api/register')
|
@POST('/api/register')
|
||||||
Future<Map<String, String>> register({
|
Future<Map<String, String>> register({
|
||||||
|
|||||||
@@ -9,7 +9,11 @@ part 'settings_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class SettingsService {
|
abstract class SettingsService {
|
||||||
factory SettingsService(Dio dio, {String baseUrl}) = _SettingsService;
|
factory SettingsService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _SettingsService;
|
||||||
|
|
||||||
@GET('/api/profile/settings')
|
@GET('/api/profile/settings')
|
||||||
Future<ProfileSettingsModel> getProfileSettings();
|
Future<ProfileSettingsModel> getProfileSettings();
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ part 'video_call_service.g.dart';
|
|||||||
|
|
||||||
@RestApi()
|
@RestApi()
|
||||||
abstract class VideoCallService {
|
abstract class VideoCallService {
|
||||||
factory VideoCallService(Dio dio, {String baseUrl}) = _VideoCallService;
|
factory VideoCallService(
|
||||||
|
Dio dio, {
|
||||||
|
String baseUrl,
|
||||||
|
ParseErrorLogger? errorLogger,
|
||||||
|
}) = _VideoCallService;
|
||||||
|
|
||||||
@GET('/api/v2/chat/{conversation}/video-call/token')
|
@GET('/api/v2/chat/{conversation}/video-call/token')
|
||||||
Future<VideoCallTokenResponse> getParticipantToken({
|
Future<VideoCallTokenResponse> getParticipantToken({
|
||||||
|
|||||||
@@ -16,13 +16,14 @@ import 'package:flutter_portal/flutter_portal.dart';
|
|||||||
import 'package:keyboard_dismisser/keyboard_dismisser.dart';
|
import 'package:keyboard_dismisser/keyboard_dismisser.dart';
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
await AppInitializer.runAppWithSentry(() async {
|
||||||
FlutterForegroundTask.initCommunicationPort();
|
FlutterForegroundTask.initCommunicationPort();
|
||||||
VideoCallForegroundBootstrap.ensureInitialized();
|
VideoCallForegroundBootstrap.ensureInitialized();
|
||||||
await AppInitializer.initialize(buildType: AppBuildType.prod);
|
await AppInitializer.initialize(buildType: AppBuildType.prod);
|
||||||
await sl<VideoCallCallKitCoordinator>().initialize();
|
await sl<VideoCallCallKitCoordinator>().initialize();
|
||||||
await PushNavigationHandler.initialize();
|
await PushNavigationHandler.initialize();
|
||||||
await AppInitializer.runAppWithSentry(() => runApp(const MyApp()));
|
runApp(const MyApp());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatefulWidget {
|
class MyApp extends StatefulWidget {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
name: eatvio_app
|
name: eatvio_app
|
||||||
description: A new Flutter project.
|
description: A new Flutter project.
|
||||||
version: 1.3.74+163
|
version: 1.3.75+164
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
311
test/core/error_reporting/api_response_reporting_test.dart
Normal file
311
test/core/error_reporting/api_response_reporting_test.dart
Normal file
@@ -0,0 +1,311 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:eatvio_app/core/app_initializer.dart';
|
||||||
|
import 'package:eatvio_app/core/di/app_config_registration.dart';
|
||||||
|
import 'package:eatvio_app/core/di/external_registrations.dart';
|
||||||
|
import 'package:eatvio_app/core/di/repository_registrations.dart';
|
||||||
|
import 'package:eatvio_app/core/di/service_registrations.dart';
|
||||||
|
import 'package:eatvio_app/core/error_reporting/error_report_policy.dart';
|
||||||
|
import 'package:eatvio_app/core/locator_service.dart';
|
||||||
|
import 'package:eatvio_app/core/prefs_keys.dart';
|
||||||
|
import 'package:eatvio_app/core/routing/other_routes.dart';
|
||||||
|
import 'package:eatvio_app/core/routing/route_constants.dart';
|
||||||
|
import 'package:eatvio_app/core/token_storage.dart';
|
||||||
|
import 'package:eatvio_app/features/notifications/models/notification_model.dart';
|
||||||
|
import 'package:eatvio_app/features/notifications/service/notifications_service.dart';
|
||||||
|
import 'package:eatvio_app/features/payment/repositories/payment_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||||
|
import 'package:eatvio_app/features/recipe/presentation/cubit/about_recipe_cubit.dart';
|
||||||
|
import 'package:eatvio_app/features/recipe/presentation/cubit/about_recipe_state.dart';
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
|
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
late _MemoryTransport transport;
|
||||||
|
late List<SentryEvent> events;
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
transport = _MemoryTransport();
|
||||||
|
events = [];
|
||||||
|
await Sentry.init((options) {
|
||||||
|
options.dsn = 'https://test@example.invalid/1';
|
||||||
|
options.transport = transport;
|
||||||
|
options.sendClientReports = false;
|
||||||
|
// Проверяем дедупликацию в приложении независимо от кеша SDK.
|
||||||
|
options.enableDeduplication = false;
|
||||||
|
options.beforeSend = (event, hint) {
|
||||||
|
final prepared = ErrorReportPolicy.prepareSentryEvent(event, hint);
|
||||||
|
if (prepared != null) events.add(prepared);
|
||||||
|
return prepared;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
dotenv.loadFromString(
|
||||||
|
envString: 'DEV_BASE_URL=https://api.example.invalid',
|
||||||
|
);
|
||||||
|
SharedPreferences.setMockInitialValues({
|
||||||
|
PrefsKeys.welcomeScreenWasShowed.name: true,
|
||||||
|
'token': 'synthetic-token',
|
||||||
|
});
|
||||||
|
AppConfigRegistration.registerAppConfig(buildType: AppBuildType.tests);
|
||||||
|
ExternalRegistrations.registerAll();
|
||||||
|
ServiceRegistrations.registerAll();
|
||||||
|
RepositoryRegistrations.registerAll();
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() async {
|
||||||
|
TokenStorage.clearCache();
|
||||||
|
await sl.reset();
|
||||||
|
await Sentry.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'reports a missing recipe field once and keeps the original stack',
|
||||||
|
() async {
|
||||||
|
sl<Dio>().httpClientAdapter = _ResponseAdapter(200, '{}');
|
||||||
|
final cubit = AboutRecipeCubit(
|
||||||
|
recipeRepository: sl(),
|
||||||
|
profileRepository: sl(),
|
||||||
|
);
|
||||||
|
addTearDown(cubit.close);
|
||||||
|
|
||||||
|
await cubit.initRecipe('private-recipe-id');
|
||||||
|
await transport.waitForEvent();
|
||||||
|
|
||||||
|
expect(cubit.state, isA<RecipeStateError>());
|
||||||
|
expect(events.single.tags?['origin'], 'api_response');
|
||||||
|
expect(
|
||||||
|
events.single.exceptions!.single.stackTrace!.frames.any(
|
||||||
|
(frame) => frame.fileName?.endsWith('recipes_model.g.dart') ?? false,
|
||||||
|
),
|
||||||
|
isTrue,
|
||||||
|
);
|
||||||
|
expect(transport.sent, hasLength(1));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'reports a malformed profile even when the welcome redirect handles it',
|
||||||
|
() async {
|
||||||
|
final adapter = _ResponseAdapter(200, '{}');
|
||||||
|
sl<Dio>().httpClientAdapter = adapter;
|
||||||
|
final route = OtherRoutes.createRoutes().whereType<GoRoute>().singleWhere(
|
||||||
|
(route) => route.path == RouteConstants.welcomeScreen,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
await route.redirect!(_BuildContext(), _RouterState()),
|
||||||
|
RouteConstants.authScreen,
|
||||||
|
);
|
||||||
|
await transport.waitForEvent();
|
||||||
|
|
||||||
|
expect(adapter.requests.single.path, '/api/profile/index');
|
||||||
|
expect(events.single.exceptions!.single.value, contains('TypeError'));
|
||||||
|
expect(transport.sent, hasLength(1));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'reports invalid JSON without sending its contents or HTTP breadcrumbs',
|
||||||
|
() async {
|
||||||
|
const secret = 'private-patient-data';
|
||||||
|
sl<Dio>().httpClientAdapter = _ResponseAdapter(200, '{"$secret":');
|
||||||
|
await Sentry.addBreadcrumb(
|
||||||
|
Breadcrumb.http(
|
||||||
|
url: Uri.parse('https://api.example.invalid/user/$secret'),
|
||||||
|
method: 'GET',
|
||||||
|
httpQuery: 'profile=$secret',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await expectLater(
|
||||||
|
sl<ProfileRepository>().getMyProfile(),
|
||||||
|
throwsA(isA<DioException>()),
|
||||||
|
);
|
||||||
|
await transport.waitForEvent();
|
||||||
|
|
||||||
|
final event = events.single;
|
||||||
|
expect(event.exceptions!.single.value, contains('FormatException'));
|
||||||
|
expect(event.exceptions!.single.stackTrace!.frames, isNotEmpty);
|
||||||
|
expect(event.tags?['origin'], 'api_response');
|
||||||
|
expect(
|
||||||
|
event.contexts['report_extras'],
|
||||||
|
containsPair('http_status_code', '200'),
|
||||||
|
);
|
||||||
|
expect(jsonEncode(event.toJson()), isNot(contains(secret)));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'reports the wrong JSON root type before the Retrofit model parser',
|
||||||
|
() async {
|
||||||
|
sl<Dio>().httpClientAdapter = _ResponseAdapter(200, '[]');
|
||||||
|
|
||||||
|
await expectLater(
|
||||||
|
sl<ProfileRepository>().getMyProfile(),
|
||||||
|
throwsA(isA<DioException>()),
|
||||||
|
);
|
||||||
|
await transport.waitForEvent();
|
||||||
|
|
||||||
|
expect(events.single.exceptions!.single.value, contains('TypeError'));
|
||||||
|
expect(
|
||||||
|
events.single.contexts['report_extras'],
|
||||||
|
containsPair('http_status_code', '200'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'reports a malformed notification and keeps the replacement item',
|
||||||
|
() async {
|
||||||
|
sl<Dio>().httpClientAdapter = _ResponseAdapter(
|
||||||
|
200,
|
||||||
|
'{"data":[17],"current_page":1,"last_page":1,"per_page":20,"total":1}',
|
||||||
|
);
|
||||||
|
|
||||||
|
final result = await sl<NotificationsService>().getNotifications(page: 1);
|
||||||
|
await transport.waitForEvent();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
(result!['notifications'] as List).single,
|
||||||
|
isA<UnknownNotification>(),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
events.single.contexts['report_extras'],
|
||||||
|
containsPair('endpoint', '/api/profile/notifications'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'reports an invalid minimum version and still skips the update screen',
|
||||||
|
() async {
|
||||||
|
PackageInfo.setMockInitialValues(
|
||||||
|
appName: 'Eatvio',
|
||||||
|
packageName: 'example.invalid',
|
||||||
|
version: '1.0.0',
|
||||||
|
buildNumber: '1',
|
||||||
|
buildSignature: '',
|
||||||
|
);
|
||||||
|
sl<Dio>().httpClientAdapter = _ResponseAdapter(
|
||||||
|
200,
|
||||||
|
'{"min_version":"invalid"}',
|
||||||
|
);
|
||||||
|
final route = OtherRoutes.createRoutes().whereType<GoRoute>().singleWhere(
|
||||||
|
(route) => route.path == RouteConstants.updateScreen,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
await route.redirect!(_BuildContext(), _RouterState()),
|
||||||
|
RouteConstants.welcomeScreen,
|
||||||
|
);
|
||||||
|
await transport.waitForEvent();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
events.single.contexts['report_extras'],
|
||||||
|
containsPair('endpoint', '/api/app_versions'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'reports a malformed 422 promo response after its manual parse',
|
||||||
|
() async {
|
||||||
|
sl<Dio>().httpClientAdapter = _ResponseAdapter(422, '{}');
|
||||||
|
|
||||||
|
await expectLater(
|
||||||
|
sl<PaymentRepository>().applyPromoCode(
|
||||||
|
planId: 42,
|
||||||
|
promoCode: 'private',
|
||||||
|
),
|
||||||
|
throwsA(isA<TypeError>()),
|
||||||
|
);
|
||||||
|
await transport.waitForEvent();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
events.single.contexts['report_extras'],
|
||||||
|
containsPair('http_status_code', '422'),
|
||||||
|
);
|
||||||
|
expect(transport.sent, hasLength(1));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test('keeps expected 4xx quiet and captures a regular 5xx once', () async {
|
||||||
|
final dio = sl<Dio>();
|
||||||
|
final cubit = AboutRecipeCubit(
|
||||||
|
recipeRepository: sl(),
|
||||||
|
profileRepository: sl(),
|
||||||
|
);
|
||||||
|
addTearDown(cubit.close);
|
||||||
|
|
||||||
|
dio.httpClientAdapter = _ResponseAdapter(404, '{}');
|
||||||
|
await cubit.initRecipe('synthetic');
|
||||||
|
expect(events, isEmpty);
|
||||||
|
|
||||||
|
dio.httpClientAdapter = _ResponseAdapter(500, '{}');
|
||||||
|
await cubit.initRecipe('synthetic');
|
||||||
|
await transport.waitForEvent();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
events.single.exceptions!.first.mechanism!.type,
|
||||||
|
'SentryDioClientAdapter',
|
||||||
|
);
|
||||||
|
expect(transport.sent, hasLength(1));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ResponseAdapter implements HttpClientAdapter {
|
||||||
|
_ResponseAdapter(this.statusCode, this.body);
|
||||||
|
|
||||||
|
final int statusCode;
|
||||||
|
final String body;
|
||||||
|
final requests = <RequestOptions>[];
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<ResponseBody> fetch(
|
||||||
|
RequestOptions options,
|
||||||
|
Stream<Uint8List>? requestStream,
|
||||||
|
Future<void>? cancelFuture,
|
||||||
|
) async {
|
||||||
|
requests.add(options);
|
||||||
|
return ResponseBody.fromString(
|
||||||
|
body,
|
||||||
|
statusCode,
|
||||||
|
headers: {
|
||||||
|
Headers.contentTypeHeader: [Headers.jsonContentType],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void close({bool force = false}) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MemoryTransport implements Transport {
|
||||||
|
final sent = <SentryEnvelope>[];
|
||||||
|
final _firstEvent = Completer<void>();
|
||||||
|
|
||||||
|
Future<void> waitForEvent() =>
|
||||||
|
_firstEvent.future.timeout(const Duration(seconds: 2));
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<SentryId?> send(SentryEnvelope envelope) async {
|
||||||
|
sent.add(envelope);
|
||||||
|
if (!_firstEvent.isCompleted) _firstEvent.complete();
|
||||||
|
return envelope.header.eventId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _BuildContext extends Fake implements BuildContext {}
|
||||||
|
|
||||||
|
class _RouterState extends Fake implements GoRouterState {}
|
||||||
Reference in New Issue
Block a user