prepareResponse method
Future<Response>
prepareResponse(
- Response res, {
- ResponseType? responseType,
})
inherited
Implementation
Future<Response> prepareResponse(http.Response res,
{ResponseType? responseType}) async {
responseType ??= ResponseType.json;
String? warnings = res.headers['x-appwrite-warning'];
if (warnings != null) {
warnings.split(';').forEach((warning) => log('Warning: $warning'));
}
if (res.statusCode >= 400) {
if ((res.headers['content-type'] ?? '').contains('application/json')) {
final response = json.decode(res.body);
throw AppwriteException(
response['message'],
response['code'],
response['type'],
response,
);
} else {
throw AppwriteException(res.body);
}
}
dynamic data;
if ((res.headers['content-type'] ?? '').contains('application/json')) {
if (responseType == ResponseType.json) {
data = json.decode(res.body);
} else if (responseType == ResponseType.bytes) {
data = res.bodyBytes;
} else {
data = res.body;
}
} else if ((res.headers['content-type'] ?? '')
.contains('multipart/form-data')) {
data = await _parseMultipart(
res.headers['content-type']!, Stream.value(res.bodyBytes));
return Response(data: data);
} else {
if (responseType == ResponseType.bytes) {
data = res.bodyBytes;
} else {
data = res.body;
}
}
return Response(data: data);
}