Skip to content

Commit e100d50

Browse files
authored
fix(gitlab) When gitlab requests fail respond with a 400 (#13691)
Don't fail and create sentry issues when GitLab instances cannot be reached, timeout or otherwise behave poorly. Fixes SENTRY-B2C
1 parent 8df2023 commit e100d50

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/sentry/integrations/gitlab/search.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from __future__ import absolute_import
22

3+
import six
34
from rest_framework.response import Response
45

56
from sentry.api.bases.integration import IntegrationEndpoint
7+
from sentry.integrations.exceptions import ApiError
68
from sentry.models import Integration
79

810

@@ -37,15 +39,21 @@ def get(self, request, organization, integration_id):
3739
except ValueError:
3840
iids = None
3941

40-
response = installation.search_issues(query=query, project_id=project, iids=iids)
42+
try:
43+
response = installation.search_issues(query=query, project_id=project, iids=iids)
44+
except ApiError as e:
45+
return Response({'detail': six.text_type(e)}, status=400)
4146

4247
return Response([{
4348
'label': '(#%s) %s' % (i['iid'], i['title']),
4449
'value': '%s#%s' % (i['project_id'], i['iid'])
4550
} for i in response])
4651

4752
elif field == 'project':
48-
response = installation.search_projects(query)
53+
try:
54+
response = installation.search_projects(query)
55+
except ApiError as e:
56+
return Response({'detail': six.text_type(e)}, status=400)
4957
return Response([{
5058
'label': project['name_with_namespace'],
5159
'value': project['id'],

tests/sentry/integrations/gitlab/test_search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def test_search_issues_request_fails(self):
255255
'project': '5',
256256
}
257257
)
258-
assert resp.status_code == 503
258+
assert resp.status_code == 400
259259

260260
def test_projects_request_fails(self):
261261
responses.add(
@@ -269,4 +269,4 @@ def test_projects_request_fails(self):
269269
'query': 'GetSentry',
270270
}
271271
)
272-
assert resp.status_code == 503
272+
assert resp.status_code == 400

0 commit comments

Comments
 (0)