Skip to content

fix(api) Don't 500 on invalid data #13587

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

Merged
merged 1 commit into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion src/sentry/api/endpoints/project_key_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ def get(self, request, project, key_id):
except ProjectKey.DoesNotExist:
raise ResourceDoesNotExist

stat_args = self._parse_args(request)
try:
stat_args = self._parse_args(request)
except ValueError:
return Response({'detail': 'Invalid request data'}, status=400)

stats = OrderedDict()
for model, name in (
Expand Down
5 changes: 5 additions & 0 deletions tests/sentry/api/endpoints/test_project_key_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def test_simple(self):
assert point['total'] == 0
assert len(response.data) == 24

def test_invalid_parameters(self):
url = self.path + '?resolution=1x'
response = self.client.get(url)
assert response.status_code == 400

# This test can be removed once the TSDB metrics that were stored
# under str(key_id) have expired out of redis.
def test_str_key_id(self):
Expand Down