Merge branch 'client-fix-timeout-exception' into 'master'

[Client] Fix timeout exception

See merge request famedly/famedlysdk!245
This commit is contained in:
Christian Pauly 2020-03-25 10:14:19 +00:00
commit 7e8586e649
3 changed files with 23 additions and 14 deletions

View file

@ -825,26 +825,35 @@ class Client {
try {
switch (type.toString().split('.').last) {
case "GET":
resp = await httpClient
.get(url, headers: headers)
.timeout(Duration(seconds: timeout));
resp = await httpClient.get(url, headers: headers).timeout(
Duration(seconds: timeout),
onTimeout: () => null,
);
break;
case "POST":
resp = await httpClient
.post(url, body: json, headers: headers)
.timeout(Duration(seconds: timeout));
resp =
await httpClient.post(url, body: json, headers: headers).timeout(
Duration(seconds: timeout),
onTimeout: () => null,
);
break;
case "PUT":
resp = await httpClient
.put(url, body: json, headers: headers)
.timeout(Duration(seconds: timeout));
resp =
await httpClient.put(url, body: json, headers: headers).timeout(
Duration(seconds: timeout),
onTimeout: () => null,
);
break;
case "DELETE":
resp = await httpClient
.delete(url, headers: headers)
.timeout(Duration(seconds: timeout));
resp = await httpClient.delete(url, headers: headers).timeout(
Duration(seconds: timeout),
onTimeout: () => null,
);
break;
}
if (resp == null) {
throw TimeoutException;
}
jsonResp = jsonDecode(String.fromCharCodes(resp.body.runes))
as Map<String, dynamic>; // May throw FormatException

View file

@ -196,7 +196,7 @@ packages:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.0+2"
version: "0.12.0+4"
http_multi_server:
dependency: transitive
description:

View file

@ -8,7 +8,7 @@ environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
http: ^0.12.0+2
http: ^0.12.0+4
mime_type: ^0.2.4
canonical_json: ^1.0.0