[Requests] Add try_catch for utf8 decoding because dart really seems to have issues with json encoding and decoding. (also use camelCase)
Took 18 minutes
This commit is contained in:
parent
9f6bd740ca
commit
3c0fbf784f
|
@ -193,8 +193,13 @@ class MatrixApi {
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var resp_body = utf8.decode(resp.bodyBytes);
|
var respBody = resp.body;
|
||||||
var jsonString = String.fromCharCodes(resp_body.runes);
|
try {
|
||||||
|
respBody = utf8.decode(resp.bodyBytes);
|
||||||
|
} catch (_) {
|
||||||
|
// No-OP
|
||||||
|
}
|
||||||
|
var jsonString = String.fromCharCodes(respBody.runes);
|
||||||
if (jsonString.startsWith('[') && jsonString.endsWith(']')) {
|
if (jsonString.startsWith('[') && jsonString.endsWith(']')) {
|
||||||
jsonString = '\{"chunk":$jsonString\}';
|
jsonString = '\{"chunk":$jsonString\}';
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,8 +231,13 @@ class Client {
|
||||||
) async {
|
) async {
|
||||||
final response = await http
|
final response = await http
|
||||||
.get('https://${MatrixIdOrDomain.domain}/.well-known/matrix/client');
|
.get('https://${MatrixIdOrDomain.domain}/.well-known/matrix/client');
|
||||||
var resp_body = utf8.decode(response.bodyBytes);
|
var respBody = response.body;
|
||||||
final rawJson = json.decode(resp_body);
|
try {
|
||||||
|
respBody = utf8.decode(response.bodyBytes);
|
||||||
|
} catch (_) {
|
||||||
|
// No-OP
|
||||||
|
}
|
||||||
|
final rawJson = json.decode(respBody);
|
||||||
return WellKnownInformations.fromJson(rawJson);
|
return WellKnownInformations.fromJson(rawJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue