Merge branch 'client-fix-timeout-exception' into 'master'
[Client] Fix timeout exception See merge request famedly/famedlysdk!245
This commit is contained in:
commit
7e8586e649
|
@ -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
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue