21 lines
585 B
Dart
21 lines
585 B
Dart
import 'package:dio/dio.dart';
|
|
|
|
String? kratosReason(Object e) {
|
|
if (e is! DioException) return null;
|
|
final body = e.response?.data;
|
|
if (body is Map && body['reason'] is String) return body['reason'] as String;
|
|
return null;
|
|
}
|
|
|
|
String kratosDisplayMessage(Object e, {required String fallback}) {
|
|
if (kratosReason(e) == 'INTERNAL_ERROR') return fallback;
|
|
if (e is DioException) {
|
|
final body = e.response?.data;
|
|
if (body is Map && body['message'] is String) {
|
|
final m = body['message'] as String;
|
|
if (m.isNotEmpty) return m;
|
|
}
|
|
}
|
|
return fallback;
|
|
}
|