Add request to ErrorResponse class

This commit is contained in:
Christian Pauly 2019-06-11 12:31:50 +02:00
parent 1962897ddb
commit 8983cb3138
2 changed files with 14 additions and 7 deletions

View file

@ -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<String, dynamic> jsonResp;
@ -219,11 +220,11 @@ class Connection {
jsonResp = jsonDecode(resp.body) as Map<String, dynamic>;
} 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;

View file

@ -21,6 +21,8 @@
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
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<String, dynamic> json) {
ErrorResponse({this.errcode, this.error, this.request});
ErrorResponse.fromJson(Map<String, dynamic> json, http.Request newRequest) {
errcode = json['errcode'];
error = json['error'] ?? "";
request = newRequest;
}
Map<String, dynamic> toJson() {