HttpResponse constructor
- {required BaseResponse response,
- required HttpRequest request,
- required Uint8List body}
Create a new HttpResponse.
This class is a wrapper around BaseResponse from package:http
providing support for errors
and for parsing the received body.
Implementation
HttpResponse({
required this.response,
required this.request,
required this.body,
}) : statusCode = response.statusCode,
headers = response.headers {
String? textBody;
dynamic jsonBody;
bool hasJsonBody = false;
try {
textBody = utf8.decode(body);
jsonBody = jsonDecode(textBody);
hasJsonBody = true;
} on FormatException {
// ignore: Invalid format, leave the defaults
}
this.textBody = textBody;
this.jsonBody = jsonBody;
this.hasJsonBody = hasJsonBody;
}