Skip to content

Commit 40299af

Browse files
authored
fix(feedback): parse JSON after checking status code (#103167)
fixes a bunch of noisy `JSONDecodeErrors` in title gen, label gen, and spam detection that were happening because we tried to JSON decode 500 responses: https://sentry.sentry.io/issues/6977994202/?query=%22jsondecodeerror%22&referrer=issue-stream https://sentry.sentry.io/issues/6978011530/?query=%22jsondecodeerror%22&referrer=issue-stream https://sentry.sentry.io/issues/6978011522/?query=%22jsondecodeerror%22&referrer=issue-stream https://sentry.sentry.io/issues/6978011504/?query=%22jsondecodeerror%22&referrer=issue-stream `response.json()` calls are now outside try/catch which SHOULD be safe because by the time we get here, the status code is 200. This pattern matches what's currently in [`organization_feedback_summary.py`](https://github.com/getsentry/sentry/blob/b91b6e10dd3812b081ca3b317b8923bca709e796/src/sentry/feedback/endpoints/organization_feedback_summary.py#L64).
1 parent 49b7c13 commit 40299af

File tree

4 files changed

+4
-9
lines changed

4 files changed

+4
-9
lines changed

src/sentry/feedback/endpoints/organization_feedback_categories.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ def get(self, request: Request, organization: Organization) -> Response:
219219
timeout=SEER_TIMEOUT_S,
220220
retries=SEER_RETRIES,
221221
)
222-
response_data = response.json()
223222
except Exception:
224223
logger.exception("Seer failed to generate user feedback label groups")
225224
return Response(
@@ -233,7 +232,7 @@ def get(self, request: Request, organization: Organization) -> Response:
233232
return Response(
234233
{"detail": "Failed to generate user feedback label groups"}, status=500
235234
)
236-
label_groups = response_data["data"]
235+
label_groups = response.json()["data"]
237236
else:
238237
# If there are less than THRESHOLD_TO_GET_ASSOCIATED_LABELS feedbacks, we don't ask for associated labels
239238
# The more feedbacks there are, the LLM does a better job of generating associated labels since it has more context

src/sentry/feedback/usecases/label_generation.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def generate_labels(feedback_message: str, organization_id: int) -> list[str]:
4646
timeout=SEER_TIMEOUT_S,
4747
retries=SEER_RETRIES,
4848
)
49-
response_data = response.json()
5049
except Exception:
5150
logger.exception("Seer failed to generate user feedback labels")
5251
raise
@@ -58,7 +57,5 @@ def generate_labels(feedback_message: str, organization_id: int) -> list[str]:
5857
)
5958
raise Exception("Seer returned non-200 response")
6059

61-
labels = response_data["data"]["labels"]
62-
6360
# Guaranteed to be a list of strings (validated in Seer)
64-
return labels
61+
return response.json()["data"]["labels"]

src/sentry/feedback/usecases/spam_detection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def is_spam_seer(message: str, organization_id: int) -> bool | None:
3535
timeout=SEER_TIMEOUT_S,
3636
retries=SEER_RETRIES,
3737
)
38-
response_data = response.json()
3938
except Exception:
4039
logger.exception("Seer failed to check if message is spam")
4140
return None
@@ -47,6 +46,7 @@ def is_spam_seer(message: str, organization_id: int) -> bool | None:
4746
)
4847
return None
4948

49+
response_data = response.json()
5050
if (
5151
not isinstance(response_data, dict)
5252
or "is_spam" not in response_data

src/sentry/feedback/usecases/title_generation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def get_feedback_title_from_seer(feedback_message: str, organization_id: int) ->
7777
timeout=SEER_TIMEOUT_S,
7878
retries=SEER_RETRIES,
7979
)
80-
response_data = response.json()
8180
except Exception:
8281
return None
8382

@@ -93,7 +92,7 @@ def get_feedback_title_from_seer(feedback_message: str, organization_id: int) ->
9392
return None
9493

9594
try:
96-
return response_data["title"].strip() or None
95+
return response.json()["title"].strip() or None
9796
except Exception:
9897
return None
9998

0 commit comments

Comments
 (0)