[Client] Fix timeout exception

This commit is contained in:
Christian Pauly 2020-03-25 11:03:47 +01:00
parent 29398360b3
commit 44993f3506
3 changed files with 23 additions and 14 deletions

View file

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

View file

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

View file

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