import 'package:dio/dio.dart'; import 'api_exception.dart'; String? kratosReason(Object e) { if (e is DioException || e is ApiException || e is FormatException) { return ApiException.from(e).reason; } return null; } String kratosDisplayMessage(Object e, {required String fallback}) { if (kratosReason(e) == 'INTERNAL_ERROR') return fallback; final exception = ApiException.from(e); if (exception.serverMessage case final message? when message.isNotEmpty) { return message; } return fallback; } abstract final class ErrorMessageMapper { static String message(Object error, {required String fallback}) => kratosDisplayMessage(error, fallback: fallback); }