handleResponse static method
dynamic
handleResponse(
- Response response
Implementation
static dynamic handleResponse(http.Response response) {
String body = response.body;
switch (response.statusCode) {
case 200:
if (body != '') {
return json.decode(body);
}
return {};
case 400:
throw BadRequestException(response.body.toString());
case 401:
case 403:
throw UnauthorizedException(response.body.toString());
case 500:
default:
if (body != '') {
throw FetchDataException('$body, status: ${response.statusCode}');
} else {
throw FetchDataException('An unexpected error occurred');
}
}
}