In my Airflow dag, I am doing this:
try:
response = requests.get(url, params=params, headers=headers)
if response.status_code == 403:
raise Exception(f"Data Unavailable for metric: {m}, account: {account}")
except Exception as e:
logging.info(f"Exception during API request: {e} for metric: {m}, account: {account}")
The except Exception as e:
part only runs when there's an error from the API for example a wrong API etc. However, in case of if response.status_code == 403
, the DAG does not fail, even though I manually wrote a "raise Exception". It just moves on to the next steps and shows green or "success" for that task.
How can I force the DAG to fail, throw an error and stop if this error occurs?