fix: Parsing of MatrixException parameters
This commit is contained in:
parent
855f9ee2e6
commit
6948eb8c06
|
|
@ -24,6 +24,7 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:matrix_api_lite/matrix_api_lite.dart';
|
||||||
|
|
||||||
enum MatrixError {
|
enum MatrixError {
|
||||||
M_UNKNOWN,
|
M_UNKNOWN,
|
||||||
|
|
@ -65,12 +66,12 @@ class MatrixException implements Exception {
|
||||||
|
|
||||||
/// The unique identifier for this error.
|
/// The unique identifier for this error.
|
||||||
String get errcode =>
|
String get errcode =>
|
||||||
raw['errcode'] as String? ??
|
raw.tryGet<String>('errcode') ??
|
||||||
(requireAdditionalAuthentication ? 'M_FORBIDDEN' : 'M_UNKNOWN');
|
(requireAdditionalAuthentication ? 'M_FORBIDDEN' : 'M_UNKNOWN');
|
||||||
|
|
||||||
/// A human readable error description.
|
/// A human readable error description.
|
||||||
String get errorMessage =>
|
String get errorMessage =>
|
||||||
raw['error'] as String? ??
|
raw.tryGet<String>('error') ??
|
||||||
(requireAdditionalAuthentication
|
(requireAdditionalAuthentication
|
||||||
? 'Require additional authentication'
|
? 'Require additional authentication'
|
||||||
: 'Unknown error');
|
: 'Unknown error');
|
||||||
|
|
@ -91,11 +92,11 @@ class MatrixException implements Exception {
|
||||||
(e) => e.toString() == 'MatrixError.${(raw["errcode"] ?? "")}',
|
(e) => e.toString() == 'MatrixError.${(raw["errcode"] ?? "")}',
|
||||||
orElse: () => MatrixError.M_UNKNOWN);
|
orElse: () => MatrixError.M_UNKNOWN);
|
||||||
|
|
||||||
int? get retryAfterMs => raw['retry_after_ms'] as int?;
|
int? get retryAfterMs => raw.tryGet<int>('retry_after_ms');
|
||||||
|
|
||||||
/// This is a session identifier that the client must pass back to the homeserver, if one is provided,
|
/// This is a session identifier that the client must pass back to the homeserver, if one is provided,
|
||||||
/// in subsequent attempts to authenticate in the same API call.
|
/// in subsequent attempts to authenticate in the same API call.
|
||||||
String? get session => raw['session'] as String?;
|
String? get session => raw.tryGet<String>('session');
|
||||||
|
|
||||||
/// Returns true if the server requires additional authentication.
|
/// Returns true if the server requires additional authentication.
|
||||||
bool get requireAdditionalAuthentication => response != null
|
bool get requireAdditionalAuthentication => response != null
|
||||||
|
|
@ -105,26 +106,24 @@ class MatrixException implements Exception {
|
||||||
/// For each endpoint, a server offers one or more 'flows' that the client can use
|
/// For each endpoint, a server offers one or more 'flows' that the client can use
|
||||||
/// to authenticate itself. Each flow comprises a series of stages. If this request
|
/// to authenticate itself. Each flow comprises a series of stages. If this request
|
||||||
/// doesn't need additional authentication, then this is null.
|
/// doesn't need additional authentication, then this is null.
|
||||||
List<AuthenticationFlow>? get authenticationFlows {
|
List<AuthenticationFlow>? get authenticationFlows => raw
|
||||||
final flows = raw['flows'];
|
.tryGet<List<dynamic>>('flows')
|
||||||
return (flows is List<Map<String, List<String>>>)
|
?.whereType<Map<String, dynamic>>()
|
||||||
? flows
|
|
||||||
.map((flow) => flow['stages'])
|
.map((flow) => flow['stages'])
|
||||||
.whereType<List<String>>()
|
.whereType<List<dynamic>>()
|
||||||
.map((stages) => AuthenticationFlow(List<String>.from(stages)))
|
.map((stages) =>
|
||||||
.toList()
|
AuthenticationFlow(List<String>.from(stages.whereType<String>())))
|
||||||
: null;
|
.toList();
|
||||||
}
|
|
||||||
|
|
||||||
/// This section contains any information that the client will need to know in order to use a given type
|
/// This section contains any information that the client will need to know in order to use a given type
|
||||||
/// of authentication. For each authentication type presented, that type may be present as a key in this
|
/// of authentication. For each authentication type presented, that type may be present as a key in this
|
||||||
/// dictionary. For example, the public part of an OAuth client ID could be given here.
|
/// dictionary. For example, the public part of an OAuth client ID could be given here.
|
||||||
Map<String, dynamic>? get authenticationParams =>
|
Map<String, dynamic>? get authenticationParams =>
|
||||||
raw['params'] as Map<String, dynamic>?;
|
raw.tryGetMap<String, dynamic>('params');
|
||||||
|
|
||||||
/// Returns the list of already completed authentication flows from previous requests.
|
/// Returns the list of already completed authentication flows from previous requests.
|
||||||
List<String> get completedAuthenticationFlows =>
|
List<String> get completedAuthenticationFlows =>
|
||||||
List<String>.from(raw['completed'] as List<String>? ?? []);
|
raw.tryGetList<String>('completed') ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For each endpoint, a server offers one or more 'flows' that the client can use
|
/// For each endpoint, a server offers one or more 'flows' that the client can use
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue