[Client] Fix timeout exception
This commit is contained in:
parent
29398360b3
commit
44993f3506
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue