request method
Make a GET HTTP request to DAAP server.
Throws DaapAuthRequiredException in case of server auth required. Throws DaapAuthenticationFailureException in case of wrong credentials provided. Throws DaapTooManyConnectionsException in case of server overload. Throws DaapException in case of unexpected response status code or network error.
Implementation
Future<Uint8List> request(Uri url) async {
try {
var response = await connection!.get(url, headers: headers);
if (response.statusCode == HttpStatus.unauthorized) {
throw DaapAuthRequiredException();
} else if (response.statusCode == HttpStatus.forbidden) {
throw DaapAuthenticationFailureException();
} else if (response.statusCode == HttpStatus.serviceUnavailable) {
throw DaapTooManyConnectionsException();
} else if (response.statusCode == HttpStatus.noContent) {
return Uint8List.fromList([]);
} else if (response.statusCode != HttpStatus.ok) {
throw DaapException(
// ignore: lines_longer_than_80_chars
"Response status: '${response.statusCode}'. Response content: '${utf8.decode(response.bodyBytes)}'.");
} else {
return response.bodyBytes;
}
} on ClientException {
throw DaapException("Client error.");
} on SocketException {
throw DaapException("Socket error.");
}
}