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:
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();
|
||||
}
|
||||
Reference in New Issue
Block a user