diff --git a/lib/src/model/matrix_exception.dart b/lib/src/model/matrix_exception.dart index 28e14445..48231e3e 100644 --- a/lib/src/model/matrix_exception.dart +++ b/lib/src/model/matrix_exception.dart @@ -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('retry_after_ms'); diff --git a/test/matrix_api_test.dart b/test/matrix_api_test.dart index 57454e72..fe5a69b4 100644 --- a/test/matrix_api_test.dart +++ b/test/matrix_api_test.dart @@ -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'); });