2021-12-03 17:29:32 +01:00
|
|
|
//@dart=2.12
|
|
|
|
|
2021-02-13 09:56:16 +01:00
|
|
|
import 'dart:io';
|
|
|
|
|
2020-12-25 09:58:34 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
|
2020-12-25 09:58:34 +01:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:matrix/matrix.dart';
|
2020-12-25 09:58:34 +01:00
|
|
|
|
2021-10-30 14:06:10 +02:00
|
|
|
import 'uia_request_manager.dart';
|
|
|
|
|
2020-12-25 09:58:34 +01:00
|
|
|
extension LocalizedExceptionExtension on Object {
|
|
|
|
String toLocalizedString(BuildContext context) {
|
|
|
|
if (this is MatrixException) {
|
|
|
|
switch ((this as MatrixException).error) {
|
|
|
|
case MatrixError.M_FORBIDDEN:
|
2021-12-03 17:29:32 +01:00
|
|
|
return L10n.of(context)!.noPermission;
|
2020-12-25 09:58:34 +01:00
|
|
|
case MatrixError.M_LIMIT_EXCEEDED:
|
2021-12-03 17:29:32 +01:00
|
|
|
return L10n.of(context)!.tooManyRequestsWarning;
|
2020-12-25 09:58:34 +01:00
|
|
|
default:
|
|
|
|
return (this as MatrixException).errorMessage;
|
|
|
|
}
|
|
|
|
}
|
2021-02-13 09:56:16 +01:00
|
|
|
if (this is BadServerVersionsException) {
|
|
|
|
final serverVersions = (this as BadServerVersionsException)
|
|
|
|
.serverVersions
|
|
|
|
.toString()
|
|
|
|
.replaceAll('{', '"')
|
|
|
|
.replaceAll('}', '"');
|
|
|
|
final supportedVersions = (this as BadServerVersionsException)
|
|
|
|
.supportedVersions
|
|
|
|
.toString()
|
|
|
|
.replaceAll('{', '"')
|
|
|
|
.replaceAll('}', '"');
|
2021-12-03 17:29:32 +01:00
|
|
|
return L10n.of(context)!
|
2021-02-13 09:56:16 +01:00
|
|
|
.badServerVersionsException(serverVersions, supportedVersions);
|
|
|
|
}
|
|
|
|
if (this is BadServerLoginTypesException) {
|
|
|
|
final serverVersions = (this as BadServerLoginTypesException)
|
|
|
|
.serverLoginTypes
|
|
|
|
.toString()
|
|
|
|
.replaceAll('{', '"')
|
|
|
|
.replaceAll('}', '"');
|
|
|
|
final supportedVersions = (this as BadServerLoginTypesException)
|
|
|
|
.supportedLoginTypes
|
|
|
|
.toString()
|
|
|
|
.replaceAll('{', '"')
|
|
|
|
.replaceAll('}', '"');
|
2021-12-03 17:29:32 +01:00
|
|
|
return L10n.of(context)!
|
2021-02-13 09:56:16 +01:00
|
|
|
.badServerLoginTypesException(serverVersions, supportedVersions);
|
|
|
|
}
|
|
|
|
if (this is MatrixConnectionException || this is SocketException) {
|
2021-12-03 17:29:32 +01:00
|
|
|
return L10n.of(context)!.noConnectionToTheServer;
|
2020-12-25 09:58:34 +01:00
|
|
|
}
|
2021-11-14 13:56:36 +01:00
|
|
|
if (this is String) return toString();
|
2021-10-30 14:06:10 +02:00
|
|
|
if (this is UiaException) return toString();
|
2021-02-06 20:41:24 +01:00
|
|
|
Logs().w('Something went wrong: ', this);
|
2021-12-03 17:29:32 +01:00
|
|
|
return L10n.of(context)!.oopsSomethingWentWrong;
|
2020-12-25 09:58:34 +01:00
|
|
|
}
|
|
|
|
}
|