You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FastAPI's HTTPExceptions do not get sent with the error message as subtitle #2192
Create 2 simple FastAPI routes that raise exceptions like this:
@router.get("/http-exception")asyncdeftrigger_http_exception():
raiseHTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Intentional HTTPException, please ignore",
)
classMyHTTPException(HTTPException):
"""This class should be used to throw our custom HTTPExceptions, as the base class does not provide the error message to Sentry"""def__init__(self, status_code: int, message: str):
super().__init__(
status_code=status_code,
detail=message,
)
self.message=message# required to make Sentry display subtitles on issues@router.get("/http-exception-cause")asyncdeftrigger_http_exception_with_cause():
raiseMyHTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
message="Intentional HTTPExceptionWithCause, please ignore",
)
Call the endpoint at /http-exception
Call the endpoint at /http-exception-cause
Go to Sentry's issue page, and confirm that only the MyHTTPException provides a subtitle for the issue with the error message, and the HTTPException does not.
I also contacted Sentry support and they also confirmed this is a bug.
Expected Result
Both exceptions should show the error message as the subtitle in the issue. On FastAPI HTTPExceptions this is called detail.
Actual Result
Only the custom MyHTTPException has the subtitle in Sentry issues.
I debugged printing the event on the before_send function and the event.exception.values[0].value as an empty string for HTTPExceptions:
This is not the case with our custom exceptions, that as a workaround set the message field.
Hey @nicolassanmar, thanks for opening this, it'd definitely be nice to have the detail treated the same way we do messages. PRs are always welcome if you or anyone reading this feel like giving it a shot! We could either fix this in the Starlette integration, or more generally whenever we format the exception value and there's no message, but there is a detail.
This is an excellent Issue raised! I have also encountered the same issue and am working around it with using Python's Exception class for now. But this really does need to be solved.
raise HTTPException() from fastAPI does not send error report to sentry. however, invoking capture_error(HTTPException()) does. But then the details within the HTTPException do not get transmitted.
Status update: there's an open pull request for this, but it needs some changes and the original contributor hasn't had time -- we'll take a look at it and finish it when time permits.
Activity
sentrivana commentedon Jun 23, 2023
Hey @nicolassanmar, thanks for opening this, it'd definitely be nice to have the
detailtreated the same way we domessages. PRs are always welcome if you or anyone reading this feel like giving it a shot! We could either fix this in the Starlette integration, or more generally whenever we format the exception value and there's nomessage, but there is adetail.fix: Exceptions include `detail` property for their value
goharShoukat commentedon Jul 26, 2023
This is an excellent Issue raised! I have also encountered the same issue and am working around it with using Python's Exception class for now. But this really does need to be solved.
raise HTTPException()from fastAPI does not send error report to sentry. however, invokingcapture_error(HTTPException())does. But then the details within the HTTPException do not get transmitted.sentrivana commentedon Aug 2, 2023
Status update: there's an open pull request for this, but it needs some changes and the original contributor hasn't had time -- we'll take a look at it and finish it when time permits.