forked from eatvio/eatvio_app
feat(app): refactoring of sentry using, feat(become_consultant): fixed possible infinite loading, feat(push_notifications): fixed push navigation from paid plan push
This commit is contained in:
@@ -9,9 +9,11 @@ import 'package:eatvio_app/core/prefs.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/features/registration/models/user_registration_model.dart';
|
||||
import 'package:eatvio_app/features/registration/presentation/bloc/registration_cubit/registration_state.dart';
|
||||
import 'package:eatvio_app/features/registration/registration_error_message.dart';
|
||||
import 'package:eatvio_app/features/registration/repositories/registration_repository.dart';
|
||||
import 'package:eatvio_app/features/registration/services/registration_analytics_service.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:eatvio_app/core/error_reporting/report_from.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class RegistrationCubit extends Cubit<RegistrationState> with RegistrationDateCacheMixin {
|
||||
@@ -65,9 +67,11 @@ class RegistrationCubit extends Cubit<RegistrationState> with RegistrationDateCa
|
||||
cacheRegistrationDate(DateTime.now());
|
||||
AppRouter.navigatorKey.currentContext?.replaceNamed('verifyEmailScreen');
|
||||
} catch (e, st) {
|
||||
log(e.toString(), stackTrace: st);
|
||||
RegistrationAnalyticsService.reportRegistrationError(e.toString());
|
||||
emit(RegistrationState(sheet: state.sheet, error: e.toString()));
|
||||
await reportFrom(e, st, this);
|
||||
final message = registrationErrorMessage(e);
|
||||
log(message, stackTrace: st);
|
||||
RegistrationAnalyticsService.reportRegistrationError(message);
|
||||
emit(RegistrationState(sheet: state.sheet, error: message));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,8 +80,9 @@ class RegistrationCubit extends Cubit<RegistrationState> with RegistrationDateCa
|
||||
final location = (await registrationRepository.getLocationsListByQuery(query));
|
||||
emit(RegistrationState(sheet: state.sheet.copyWith(responseBody: location.responseBody)));
|
||||
return location.locations;
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,8 +91,9 @@ class RegistrationCubit extends Cubit<RegistrationState> with RegistrationDateCa
|
||||
final location = (await registrationRepository.getLocationsListByCoordinates(latitude, longitude));
|
||||
emit(RegistrationState(sheet: state.sheet.copyWith(responseBody: location.responseBody)));
|
||||
return location.locations;
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:eatvio_app/features/profile/repositories/profile_repository.dart
|
||||
import 'package:eatvio_app/features/registration/presentation/bloc/verify_email_cubit/verify_email_state.dart';
|
||||
import 'package:eatvio_app/features/registration/services/registration_analytics_service.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:eatvio_app/core/error_reporting/report_from.dart';
|
||||
|
||||
class VerifyEmailCubit extends Cubit<VerifyEmailState> {
|
||||
final ProfileRepository profileRepository;
|
||||
@@ -16,7 +17,8 @@ class VerifyEmailCubit extends Cubit<VerifyEmailState> {
|
||||
final profile = await profileRepository.getMyProfile();
|
||||
await profileRepository.sendEmailCode();
|
||||
emit(VerifyEmailState.loaded(email: profile.email));
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
emit(const VerifyEmailState.error(errorMessage: 'Ошибка отправки кода.\nПовторите попытку позже'));
|
||||
}
|
||||
}
|
||||
@@ -24,18 +26,15 @@ class VerifyEmailCubit extends Cubit<VerifyEmailState> {
|
||||
Future<void> tryVerify(String code) async {
|
||||
try {
|
||||
emit(const VerifyEmailState.verifyLoading());
|
||||
final result = await profileRepository.tryVerifyEmailByCode(code);
|
||||
if (result == true) {
|
||||
emit(const VerifyEmailState.verifySuccess());
|
||||
try {
|
||||
RegistrationAnalyticsService.reportEmailVerification();
|
||||
} catch (e) {
|
||||
// Игнорируем ошибки аналитики, верификация уже успешна
|
||||
}
|
||||
} else {
|
||||
emit(const VerifyEmailState.verifyError());
|
||||
await profileRepository.tryVerifyEmailByCode(code);
|
||||
emit(const VerifyEmailState.verifySuccess());
|
||||
try {
|
||||
RegistrationAnalyticsService.reportEmailVerification();
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
emit(const VerifyEmailState.verifyError());
|
||||
}
|
||||
}
|
||||
@@ -47,7 +46,8 @@ class VerifyEmailCubit extends Cubit<VerifyEmailState> {
|
||||
emit(const VerifyEmailState.changeEmailSuccess());
|
||||
// Обновляем email в состоянии после успешной смены
|
||||
emit(VerifyEmailState.loaded(email: newEmail));
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
emit(const VerifyEmailState.changeEmailError());
|
||||
}
|
||||
}
|
||||
|
||||
35
lib/features/registration/registration_error_message.dart
Normal file
35
lib/features/registration/registration_error_message.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
/// Сообщение для UI / аналитики при ошибке регистрации (вызывать из кубита).
|
||||
String registrationErrorMessage(Object error) {
|
||||
if (error is String) {
|
||||
return error;
|
||||
}
|
||||
if (error is DioException && error.response?.statusCode == 422) {
|
||||
final data = error.response?.data;
|
||||
if (data is Map<String, dynamic>) {
|
||||
var errorMsg = '';
|
||||
if (data.containsKey('message')) {
|
||||
errorMsg += '${data['message']}\n';
|
||||
}
|
||||
if (data.containsKey('errors')) {
|
||||
final errors = data['errors'];
|
||||
if (errors is Map) {
|
||||
errors.forEach((key, value) {
|
||||
if (value is List && value.isNotEmpty) {
|
||||
errorMsg += '${value.join('\n')}\n';
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (errorMsg.isNotEmpty) {
|
||||
return errorMsg.trim();
|
||||
}
|
||||
return 'Ошибка регистрации: $data';
|
||||
}
|
||||
}
|
||||
if (error is DioException) {
|
||||
return error.message ?? error.toString();
|
||||
}
|
||||
return error.toString();
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/features/registration/models/user_registration_model.dart';
|
||||
import 'package:eatvio_app/features/registration/models/location_model.dart';
|
||||
import 'package:eatvio_app/features/registration/services/registration_service.dart';
|
||||
import 'package:eatvio_app/core/env_config.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/features/registration/models/location_model.dart';
|
||||
import 'package:eatvio_app/features/registration/models/user_registration_model.dart';
|
||||
import 'package:eatvio_app/features/registration/services/registration_service.dart';
|
||||
|
||||
class RegistrationRepository {
|
||||
final RegistrationService registrationService;
|
||||
@@ -12,94 +11,36 @@ class RegistrationRepository {
|
||||
RegistrationRepository({required this.registrationService});
|
||||
|
||||
Future<String> tryRegister(UserRegistrationSheet sheet) async {
|
||||
try {
|
||||
final response = await registrationService.register(sheet: sheet.toJson());
|
||||
if (response.containsKey('token')) {
|
||||
return response['token']!;
|
||||
} else {
|
||||
// Если нет токена, но есть message или errors
|
||||
String errorMsg = '';
|
||||
if (response.containsKey('message')) {
|
||||
errorMsg += '${response['message']!}\n';
|
||||
}
|
||||
if (response.containsKey('errors')) {
|
||||
final errors = response['errors'];
|
||||
if (errors != null && errors is Map) {
|
||||
(errors as Map).forEach((key, value) {
|
||||
if (value is List && value.isNotEmpty) {
|
||||
errorMsg += '${value.join('\n')}\n';
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (errorMsg.isNotEmpty) {
|
||||
throw errorMsg.trim();
|
||||
} else {
|
||||
throw 'Ошибка регистрации: $response';
|
||||
}
|
||||
}
|
||||
} on DioException catch (e, s) {
|
||||
if (e.response != null && e.response?.statusCode == 422) {
|
||||
final data = e.response?.data;
|
||||
String errorMsg = '';
|
||||
if (data is Map<String, dynamic>) {
|
||||
if (data.containsKey('message')) {
|
||||
errorMsg += data['message'] + '\n';
|
||||
}
|
||||
if (data.containsKey('errors')) {
|
||||
final errors = data['errors'];
|
||||
if (errors != null && errors is Map) {
|
||||
(errors).forEach((key, value) {
|
||||
if (value is List && value.isNotEmpty) {
|
||||
errorMsg += '${value.join('\n')}\n';
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (errorMsg.isNotEmpty) {
|
||||
throw errorMsg.trim();
|
||||
} else {
|
||||
throw 'Ошибка регистрации: $data';
|
||||
}
|
||||
}
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
final response = await registrationService.register(sheet: sheet.toJson());
|
||||
if (response.containsKey('token')) {
|
||||
return response['token']!;
|
||||
}
|
||||
var errorMsg = '';
|
||||
if (response.containsKey('message')) {
|
||||
errorMsg += '${response['message']}\n';
|
||||
}
|
||||
if (response.containsKey('errors')) {
|
||||
errorMsg += '${response['errors']}\n';
|
||||
}
|
||||
if (errorMsg.isNotEmpty) {
|
||||
throw errorMsg.trim();
|
||||
}
|
||||
throw 'Ошибка регистрации: $response';
|
||||
}
|
||||
|
||||
Future<LocationModel> getLocationsListByQuery(String query) async {
|
||||
try {
|
||||
return (await registrationService.getLocationsByAddress(query: query));
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return registrationService.getLocationsByAddress(query: query);
|
||||
}
|
||||
|
||||
Future<LocationModel> getLocationsListByCoordinates(String latitude, String longitude) async {
|
||||
try {
|
||||
return (await registrationService.getLocationsByCoordinate(latitude: latitude, longitude: longitude));
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return registrationService.getLocationsByCoordinate(latitude: latitude, longitude: longitude);
|
||||
}
|
||||
|
||||
Future<bool> emailIsReachable(String email) async {
|
||||
try {
|
||||
final response = await sl<Dio>().getUri(Uri.parse('${EnvConfig.emailValidationApiUrl}?email=$email'));
|
||||
if (response.data['result']['reachable'] != 'invalid') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
return false;
|
||||
final response = await sl<Dio>().getUri(Uri.parse('${EnvConfig.emailValidationApiUrl}?email=$email'));
|
||||
if (response.data['result']['reachable'] != 'invalid') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user