-
Notifications
You must be signed in to change notification settings - Fork 0
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
Propagate Reporter Errors #243
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -11,7 +11,7 @@ | |||
|
||||
from mainframe.constants import mainframe_settings | ||||
from mainframe.database import get_db | ||||
from mainframe.dependencies import get_pypi_client, validate_token | ||||
from mainframe.dependencies import get_http_client, get_pypi_client, validate_token | ||||
from mainframe.json_web_token import AuthenticationData | ||||
from mainframe.models.orm import Scan | ||||
from mainframe.models.schemas import ( | ||||
|
@@ -159,6 +159,7 @@ def report_package( | |||
session: Annotated[Session, Depends(get_db)], | ||||
auth: Annotated[AuthenticationData, Depends(validate_token)], | ||||
pypi_client: Annotated[PyPIServices, Depends(get_pypi_client)], | ||||
http_client: Annotated[httpx.Client, Depends(get_http_client)], | ||||
): | ||||
""" | ||||
Report a package to PyPI. | ||||
|
@@ -218,7 +219,14 @@ def report_package( | |||
additional_information=body.additional_information, | ||||
) | ||||
|
||||
httpx.post(f"{mainframe_settings.reporter_url}/report/email", json=jsonable_encoder(report)) | ||||
response = http_client.post(f"{mainframe_settings.reporter_url}/report/email", json=jsonable_encoder(report)) | ||||
try: | ||||
response.raise_for_status() | ||||
except httpx.HTTPStatusError as err: | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's extract the logic for error checking and sending the request to a new function so it's easier to test. |
||||
detail = "Dragonfly Reporter service failed" | ||||
log.error(detail, status=err.response.status_code, message=err.response.text) | ||||
raise HTTPException(502, detail=detail) | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
else: | ||||
# We previously checked this condition, but the typechecker isn't smart | ||||
# enough to figure that out | ||||
|
@@ -231,7 +239,7 @@ def report_package( | |||
extra=dict(yara_rules=rules_matched), | ||||
) | ||||
|
||||
httpx.post(f"{mainframe_settings.reporter_url}/report/{name}", json=jsonable_encoder(report)) | ||||
http_client.post(f"{mainframe_settings.reporter_url}/report/{name}", json=jsonable_encoder(report)) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we want to check for success here also? |
||||
|
||||
log.info( | ||||
"Sent report", | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.