diff --git a/lib/src/Connection.dart b/lib/src/Connection.dart index d53e3f0..045f07c 100644 --- a/lib/src/Connection.dart +++ b/lib/src/Connection.dart @@ -182,7 +182,7 @@ class Connection { if (client.isLogged()) headers["Authorization"] = "Bearer ${client.accessToken}"; - var resp; + http.Response resp; try { switch (type) { case "GET": @@ -207,11 +207,12 @@ class Connection { break; } } on TimeoutException catch (_) { + return ErrorResponse( - error: "No connection possible...", errcode: "TIMEOUT"); + error: "No connection possible...", errcode: "TIMEOUT", request: resp.request); } catch (e) { return ErrorResponse( - error: "No connection possible...", errcode: "NO_CONNECTION"); + error: "No connection possible...", errcode: "NO_CONNECTION", request: resp.request); } Map jsonResp; @@ -219,11 +220,11 @@ class Connection { jsonResp = jsonDecode(resp.body) as Map; } catch (e) { return ErrorResponse( - error: "No connection possible...", errcode: "MALFORMED"); + error: "No connection possible...", errcode: "MALFORMED", request: resp.request); } if (jsonResp.containsKey("errcode") && jsonResp["errcode"] is String) { if (jsonResp["errcode"] == "M_UNKNOWN_TOKEN") clear(); - return ErrorResponse.fromJson(jsonResp); + return ErrorResponse.fromJson(jsonResp, resp.request); } return jsonResp; diff --git a/lib/src/responses/ErrorResponse.dart b/lib/src/responses/ErrorResponse.dart index 19f3f59..02ff30b 100644 --- a/lib/src/responses/ErrorResponse.dart +++ b/lib/src/responses/ErrorResponse.dart @@ -21,6 +21,8 @@ * along with Foobar. If not, see . */ +import 'package:http/http.dart' as http; + /// Represents a special response from the Homeserver for errors. class ErrorResponse { @@ -30,11 +32,15 @@ class ErrorResponse { /// A human readable error description. String error; - ErrorResponse({this.errcode, this.error}); + /// The frozen request which triggered this Error + http.Request request; - ErrorResponse.fromJson(Map json) { + ErrorResponse({this.errcode, this.error, this.request}); + + ErrorResponse.fromJson(Map json, http.Request newRequest) { errcode = json['errcode']; error = json['error'] ?? ""; + request = newRequest; } Map toJson() {