Skip to content

Commit b67b868

Browse files
committed
feat(api): Make InvalidParams a ParseError
1 parent a2ff6e9 commit b67b868

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/sentry/exceptions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.core.exceptions import SuspiciousOperation
2+
from rest_framework.exceptions import ParseError
23

34

45
class InvalidData(Exception):
@@ -89,5 +90,8 @@ def __init__(
8990
self.tombstone_id = tombstone_id
9091

9192

92-
class InvalidParams(Exception):
93+
class InvalidParams(ParseError):
94+
"""Inherits from ParseError so DRF automatically returns a 400 response
95+
when this exception is unhandled in a view."""
96+
9397
pass

src/sentry/rules/history/endpoints/project_rule_stats.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import Any, TypedDict
66

77
from drf_spectacular.utils import extend_schema
8-
from rest_framework.exceptions import ParseError
98
from rest_framework.request import Request
109
from rest_framework.response import Response
1110

@@ -16,7 +15,6 @@
1615
from sentry.api.utils import get_date_range_from_params
1716
from sentry.apidocs.constants import RESPONSE_FORBIDDEN, RESPONSE_NOT_FOUND, RESPONSE_UNAUTHORIZED
1817
from sentry.apidocs.parameters import GlobalParams, IssueAlertParams
19-
from sentry.exceptions import InvalidParams
2018
from sentry.models.project import Project
2119
from sentry.models.rule import Rule
2220
from sentry.rules.history import fetch_rule_hourly_stats
@@ -67,9 +65,6 @@ def get(self, request: Request, project: Project, rule: Rule | Workflow) -> Resp
6765
"""
6866
Note that results are returned in hourly buckets.
6967
"""
70-
try:
71-
start, end = get_date_range_from_params(request.GET)
72-
except InvalidParams as e:
73-
raise ParseError(detail=str(e))
68+
start, end = get_date_range_from_params(request.GET)
7469
results = fetch_rule_hourly_stats(rule, start, end)
7570
return Response(serialize(results, request.user, TimeSeriesValueSerializer()))

0 commit comments

Comments
 (0)