Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add error handling for slack api #792

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions airflow/operators/slack_operator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from slackclient import SlackClient
from airflow.models import BaseOperator
from airflow.utils import apply_defaults
from airflow.utils import apply_defaults, AirflowException
import json
import logging


class SlackAPIOperator(BaseOperator):
Expand Down Expand Up @@ -48,7 +49,10 @@ def execute(self, **kwargs):
if not self.api_params:
self.construct_api_call_params()
sc = SlackClient(self.token)
sc.api_call(self.method, **self.api_params)
rc = json.loads(sc.api_call(self.method, **self.api_params).decode('utf-8'))
if not rc['ok']:
logging.error("Slack API call failed ({})".format(rc['error']))
raise AirflowException("Slack API call failed: ({})".format(rc['error']))


class SlackAPIPostOperator(SlackAPIOperator):
Expand Down