forked from eatvio/eatvio_app
36 lines
1.1 KiB
Dart
36 lines
1.1 KiB
Dart
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();
|
|
}
|