filterResponses function
Checks a list of responses from one same POST request to different coordinators If all responses are errors, throw the error If at least 1 was successful, return it @param {Array} responsesArray - An array of responses, including errors @returns response @throws Axios Error
Implementation
http.Response? filterResponses(Set<http.Response?> responsesArray) {
Set<http.Response> invalidResponses = Set.from(responsesArray);
invalidResponses.removeWhere((res) => res.statusCode == 200);
if (invalidResponses.length == responsesArray.length) {
return responsesArray.first;
} else {
return responsesArray.firstWhere((res) => res!.statusCode == 200);
}
}