Skip to content

Conversation

@drazisil-codecov
Copy link
Contributor

@drazisil-codecov drazisil-codecov commented Jan 9, 2026

Summary

Fixes the #2 API error with ~1,400 events in 24 hours:

APIException: Github API unauthorized error: Unauthorized

Root Cause

The torngit_safe decorator catches TorngitClientError (including TorngitUnauthorizedError) and re-raises as DRF APIException. In the GraphQL error_formatter, exceptions are checked against BaseException or ServiceException - if neither, they get sent to Sentry via capture_exception.

APIException wasn't in this list, so all auth failures (expired tokens, revoked access, etc.) were being captured as errors.

Fix

Add APIException to the list of expected exception types in error_formatter. These represent client errors, not server bugs.

elif isinstance(original_error, APIException):
    # APIException from torngit_safe decorator - expected client errors
    # (e.g., unauthorized, forbidden) that shouldn't be sent to Sentry
    formatted["message"] = str(original_error.detail)
    formatted["type"] = type(original_error).__name__

Testing

  • All 15 graphql_api/tests/test_views.py tests pass

Related Sentry Issues


Note

Treats DRF APIException as expected client errors in GraphQL error formatting, preventing Sentry noise from auth-related failures.

  • Adds APIException import and handling in graphql_api/views.py:error_formatter; sets message from detail and type, and skips capture_exception
  • Keeps existing handling for BaseException/ServiceException; unexpected errors still logged and sent to Sentry

Written by Cursor Bugbot for commit e180cb5. This will update automatically on new commits. Configure here.

APIException errors from the torngit_safe decorator represent expected
client errors (e.g., unauthorized, forbidden) due to invalid/expired
tokens or permission issues. These are not server bugs and shouldn't
be sent to Sentry.

This was the #2 API error with ~1,400 events in 24 hours.

The fix adds APIException to the list of expected exception types in
the GraphQL error_formatter, alongside BaseException and ServiceException.
@sentry
Copy link

sentry bot commented Jan 9, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.77%. Comparing base (1aa11d2) to head (e180cb5).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
apps/codecov-api/graphql_api/views.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #645      +/-   ##
==========================================
- Coverage   93.78%   93.77%   -0.01%     
==========================================
  Files        1291     1291              
  Lines       46908    46912       +4     
  Branches     1517     1517              
==========================================
+ Hits        43992    43994       +2     
- Misses       2607     2609       +2     
  Partials      309      309              
Flag Coverage Δ
apiunit 96.55% <50.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codecov-notifications
Copy link

codecov-notifications bot commented Jan 9, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
apps/codecov-api/graphql_api/views.py 50.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants