fix: Edge case where MatrixException.error differs from errcode

This commit is contained in:
Christian Pauly 2022-10-14 14:11:17 +02:00
parent 881f8c3fd8
commit 3cc2f2fa4a
2 changed files with 5 additions and 4 deletions

View File

@ -87,10 +87,11 @@ class MatrixException implements Exception {
@override
String toString() => '$errcode: $errorMessage';
/// Returns the [ResponseError]. Is ResponseError.NONE if there wasn't an error.
/// Returns the errcode as an [MatrixError].
MatrixError get error => MatrixError.values.firstWhere(
(e) => e.toString() == 'MatrixError.${(raw["errcode"] ?? "")}',
orElse: () => MatrixError.M_UNKNOWN);
(e) => e.name == errcode,
orElse: () => MatrixError.M_UNKNOWN,
);
int? get retryAfterMs => raw.tryGet<int>('retry_after_ms');

View File

@ -70,7 +70,7 @@ void main() {
expect(exception.completedAuthenticationFlows, ['example.type.foo']);
expect(exception.requireAdditionalAuthentication, true);
expect(exception.retryAfterMs, null);
expect(exception.error, MatrixError.M_UNKNOWN);
expect(exception.error, MatrixError.M_FORBIDDEN);
expect(exception.errcode, 'M_FORBIDDEN');
expect(exception.errorMessage, 'Require additional authentication');
});