diff --git a/src/sentry/integrations/github/search.py b/src/sentry/integrations/github/search.py index 24cadc5cd2e251..5b3f31c7de0df9 100644 --- a/src/sentry/integrations/github/search.py +++ b/src/sentry/integrations/github/search.py @@ -52,6 +52,10 @@ def get(self, request, organization, integration_id): except ApiError as err: if err.code == 403: return Response({'detail': 'Rate limit exceeded'}, status=429) + if err.code == 422: + return Response({ + 'detail': 'Repositories could not be searched because they do not exist, or you do not have access to them.' + }, status=404) raise return Response([{ 'label': i['name'], diff --git a/tests/sentry/integrations/github/test_search.py b/tests/sentry/integrations/github/test_search.py index 3df8097c144a34..9f70319a10aecd 100644 --- a/tests/sentry/integrations/github/test_search.py +++ b/tests/sentry/integrations/github/test_search.py @@ -143,6 +143,30 @@ def test_finds_repo_results(self): {'value': 'test/exhaust', 'label': 'exhaust'} ] + @responses.activate + def test_repo_search_validation_error(self): + responses.add( + responses.GET, + self.base_url + '/search/repositories?q=org:test%20nope', + json={ + 'message': 'Validation Error', + 'errors': [ + {'message': 'Cannot search for that org'} + ] + }, + status=422 + ) + resp = self.client.get( + self.url, + data={ + 'field': 'repo', + 'query': 'nope', + 'repo': 'example', + } + ) + assert resp.status_code == 404 + assert 'detail' in resp.data + @responses.activate def test_finds_no_external_issues_results(self): responses.add(