[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:
Marcel 2020-07-20 13:43:55 +02:00
parent 9f6bd740ca
commit 3c0fbf784f
2 changed files with 14 additions and 4 deletions

View File

@ -193,8 +193,13 @@ class MatrixApi {
);
break;
}
var resp_body = utf8.decode(resp.bodyBytes);
var jsonString = String.fromCharCodes(resp_body.runes);
var respBody = resp.body;
try {
respBody = utf8.decode(resp.bodyBytes);
} catch (_) {
// No-OP
}
var jsonString = String.fromCharCodes(respBody.runes);
if (jsonString.startsWith('[') && jsonString.endsWith(']')) {
jsonString = '\{"chunk":$jsonString\}';
}

View File

@ -231,8 +231,13 @@ class Client {
) async {
final response = await http
.get('https://${MatrixIdOrDomain.domain}/.well-known/matrix/client');
var resp_body = utf8.decode(response.bodyBytes);
final rawJson = json.decode(resp_body);
var respBody = response.body;
try {
respBody = utf8.decode(response.bodyBytes);
} catch (_) {
// No-OP
}
final rawJson = json.decode(respBody);
return WellKnownInformations.fromJson(rawJson);
}