I am new to Airflow DAGs. I have a python script to fetch API calls. I have added a raise Exception in my code, if all API calls failed i.e. status_code!=200, then it should raise exception. However, in airflow logs, it is shown as INFO - [base] An error occurred: All API calls failed for all IDs and DAG succeeds. How do I make the DAG failed if all API calls fail.
Below is the sample code I have:
response = requests.get(url)
data = response.json()
if response.status_code!=200:
print(f"Error occurred for ID - Response code {response.status_code} {response.reason}")
break
if response.status_code==200:
df1 = pd.concat([df1, pd.json_normalize(data)])
else:
print(f'No data to fetch data for {reaction}:{id}')
if not df1.empty:
all_accounts_failed = False
if all_accounts_failed:
raise Exception("All API calls failed for all IDs")
raise
else:
try:
#rest of the code
Expecting the DAG to be failed however DAG succeeded with just showing it as INFO