2023-07-06 17:18:41 +03:30
|
|
|
import 'package:hiddify/core/locale/locale.dart';
|
|
|
|
|
|
|
|
|
|
// TODO: rewrite
|
|
|
|
|
mixin Failure {
|
2023-08-26 17:01:51 +03:30
|
|
|
({String type, String? message}) present(TranslationsEn t);
|
2023-07-06 17:18:41 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension ErrorPresenter on TranslationsEn {
|
2023-08-26 17:01:51 +03:30
|
|
|
String printError(Object error) {
|
|
|
|
|
if (error case Failure()) {
|
|
|
|
|
final err = error.present(this);
|
|
|
|
|
return err.type + (err.message == null ? "" : ": ${err.message}");
|
|
|
|
|
}
|
2023-07-06 17:18:41 +03:30
|
|
|
return failure.unexpected;
|
|
|
|
|
}
|
2023-08-26 17:01:51 +03:30
|
|
|
|
|
|
|
|
({String type, String? message}) presentError(Object error) {
|
|
|
|
|
if (error case Failure()) return error.present(this);
|
|
|
|
|
return (type: failure.unexpected, message: null);
|
|
|
|
|
}
|
2023-07-06 17:18:41 +03:30
|
|
|
}
|