1
1
from __future__ import absolute_import , print_function
2
2
3
+ import six
4
+
3
5
from django .core .urlresolvers import reverse
4
6
from django .db import IntegrityError
5
7
from django .http import Http404
6
8
from django .utils import timezone
7
9
from django .views .decorators .cache import never_cache
8
10
9
- from sentry import http
10
11
from sentry .models import Integration , Identity , IdentityProvider , IdentityStatus , Organization
11
12
from sentry .utils .http import absolute_uri
12
13
from sentry .utils .signing import sign , unsign
14
+ from sentry .web .decorators import transaction_start
13
15
from sentry .web .frontend .base import BaseView
14
16
from sentry .web .helpers import render_to_response
17
+ from sentry .shared_integrations .exceptions import ApiError
15
18
16
- from .utils import logger , track_response_code
19
+ from .client import SlackClient
20
+ from .utils import logger
17
21
18
22
19
23
def build_linking_url (integration , organization , slack_id , channel_id , response_url ):
@@ -31,6 +35,7 @@ def build_linking_url(integration, organization, slack_id, channel_id, response_
31
35
32
36
33
37
class SlackLinkIdentityView (BaseView ):
38
+ @transaction_start ("SlackLinkIdentityView" )
34
39
@never_cache
35
40
def handle (self , request , signed_params ):
36
41
params = unsign (signed_params .encode ("ascii" , errors = "ignore" ))
@@ -82,19 +87,18 @@ def handle(self, request, signed_params):
82
87
"text" : "Your Slack identity has been linked to your Sentry account. You're good to go!" ,
83
88
}
84
89
85
- session = http .build_session ()
86
- req = session .post (params ["response_url" ], json = payload )
87
- status_code = req .status_code
88
- resp = req .json ()
89
-
90
- # If the user took their time to link their slack account, we may no
91
- # longer be able to respond, and we're not guaranteed able to post into
92
- # the channel. Ignore Expired url errors.
93
- #
94
- # XXX(epurkhiser): Yes the error string has a space in it.
95
- if not resp .get ("ok" ) and resp .get ("error" ) != "Expired url" :
96
- logger .error ("slack.link-notify.response-error" , extra = {"response" : resp })
97
- track_response_code (status_code , resp .get ("ok" ))
90
+ client = SlackClient ()
91
+ try :
92
+ client .post (params ["response_url" ], data = payload , json = True )
93
+ except ApiError as e :
94
+ message = six .text_type (e )
95
+ # If the user took their time to link their slack account, we may no
96
+ # longer be able to respond, and we're not guaranteed able to post into
97
+ # the channel. Ignore Expired url errors.
98
+ #
99
+ # XXX(epurkhiser): Yes the error string has a space in it.
100
+ if message != "Expired url" :
101
+ logger .error ("slack.link-notify.response-error" , extra = {"error" : message })
98
102
99
103
return render_to_response (
100
104
"sentry/slack-linked.html" ,
0 commit comments