[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 {
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