-
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?
Conversation
Also make a dependency and use FastAPI dependency injection to accept the httpx.Client instance. This also makes it much 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 comment
The reason will be displayed to describe this comment to others. Learn more.
try: | ||
response.raise_for_status() | ||
except httpx.HTTPStatusError as err: |
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.
try: | |
response.raise_for_status() | |
except httpx.HTTPStatusError as err: | |
if not response.is_success: |
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want to check for success here also?
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 comment
The 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.
Contains changes from #228 + tests