requestWithTargetedResponseCode static method
Future Function()
requestWithTargetedResponseCode(
- Future<
ApiResponse> request(), - List<
int> targettedResponseCodes
Implementation
static Future<dynamic> Function() requestWithTargetedResponseCode(
Future<ApiResponse> Function() request,
List<int> targettedResponseCodes) {
return () async {
try {
var response = await request();
if (targettedResponseCodes.contains(response.statusCode)) {
// the response met the targetted response code
return;
} else {
throw Exception('Invalid response code: ${response.statusCode}');
}
} catch (e) {
rethrow;
}
};
}