4444
4545LOG = logging .getLogger (__name__ )
4646
47+ class SlackBotException (PopupException ):
48+ def __init__ (self , msg , detail = None , error_code = 200 ):
49+ PopupException .__init__ (self , message = msg , detail = detail , error_code = error_code )
50+
4751
4852@login_notrequired
4953@csrf_exempt
@@ -111,7 +115,7 @@ def _send_ephemeral_message(channel_id, user_id, raw_sql_message):
111115 try :
112116 slack_client .chat_postEphemeral (channel = channel_id , user = user_id , text = raw_sql_message )
113117 except Exception as e :
114- raise PopupException (_ ("Error posting ephemeral message" ), detail = e )
118+ raise SlackBotException (_ ("Error posting ephemeral message" ), detail = e )
115119
116120
117121def handle_on_link_shared (host_domain , channel_id , message_ts , links , user_id ):
@@ -128,10 +132,10 @@ def handle_on_link_shared(host_domain, channel_id, message_ts, links, user_id):
128132 doc = _get_gist_document (** query_id )
129133 doc_type = 'gist'
130134 else :
131- raise PopupException (_ ("Cannot unfurl link" ))
135+ raise SlackBotException (_ ("Cannot unfurl link" ))
132136 except Document2 .DoesNotExist :
133137 msg = "Document with {key} does not exist" .format (key = query_id )
134- raise PopupException (_ (msg ))
138+ raise SlackBotException (_ (msg ))
135139
136140 # Permission check for Slack user to be Hue user
137141 slack_user = check_slack_user_permission (host_domain , user_id )
@@ -144,7 +148,7 @@ def handle_on_link_shared(host_domain, channel_id, message_ts, links, user_id):
144148 try :
145149 slack_client .chat_unfurl (channel = channel_id , ts = message_ts , unfurls = payload ['payload' ])
146150 except Exception as e :
147- raise PopupException (_ ("Cannot unfurl link" ), detail = e )
151+ raise SlackBotException (_ ("Cannot unfurl link" ), detail = e )
148152
149153 # Generate and upload result xlsx file only if result available
150154 if payload ['file_status' ]:
@@ -157,14 +161,14 @@ def get_user(channel_id, slack_user):
157161 except User .DoesNotExist :
158162 bot_message = 'Corresponding Hue user not found or does not have access to the query'
159163 _send_message (channel_id , bot_message )
160- raise PopupException (_ ("Slack user does not have access to the query" ), error_code = 200 )
164+ raise SlackBotException (_ ("Slack user does not have access to the query" ))
161165
162166
163167def check_slack_user_permission (host_domain , user_id ):
164168 try :
165169 slack_user = slack_client .users_info (user = user_id )
166170 except Exception as e :
167- raise PopupException (_ ("Cannot find query owner in Slack" ), detail = e )
171+ raise SlackBotException (_ ("Cannot find query owner in Slack" ), detail = e )
168172
169173 response = {
170174 'is_bot' : slack_user ['user' ]['is_bot' ],
@@ -197,7 +201,7 @@ def send_result_file(request, channel_id, message_ts, doc, file_format):
197201 initial_comment = 'Here is your result file!'
198202 )
199203 except Exception as e :
200- raise PopupException (_ ("Cannot upload result file" ), detail = e )
204+ raise SlackBotException (_ ("Cannot upload result file" ), detail = e )
201205
202206
203207def _query_result (request , notebook , max_rows ):
0 commit comments