From 44993f35066e298f866d6ddb1208bbfdf50d0abe Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Wed, 25 Mar 2020 11:03:47 +0100 Subject: [PATCH] [Client] Fix timeout exception --- lib/src/client.dart | 33 +++++++++++++++++++++------------ pubspec.lock | 2 +- pubspec.yaml | 2 +- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index d4bc86e..2aabe99 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -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; // May throw FormatException diff --git a/pubspec.lock b/pubspec.lock index 30ef5f6..bbc0327 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index e3c0281..7296819 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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