# prefect-community

Stephen Lloyd

05/26/2022, 2:31 PM
I have a mapped task that will make an api call. What is the best way to count successful api responses? I could check the response message in the task and return an int along with the response. It seems like
will be a list of the responses and I could iterate over it in a subsequent task, but I’m hoping there is a more efficient method. Can I force a task to fail if the api indicates a failed call? If i do, is there a way to count those?
Copy code
def make_post(creds, task):
   response = requests.request('POST', ...)
   return response

with Flow(stuff, stuff):
   send_tasks =, task=data)

Kevin Kho

05/26/2022, 2:35 PM
So you can make a task fail with
raise FAIL
inside it where
is the Prefect signal. And then you can have a reduce task
Copy code
def reduce(x: List):
    total = len(x)
    fail = len[1 for _ in x if isinstance(_, BaseException)]
    success = total - fail
because the FAIL is an Exception so you can look for it like that.