Skip to content
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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Robin5605
Copy link
Contributor

Contains changes from #228 + tests

Also make a dependency and use FastAPI dependency injection to accept
the httpx.Client instance. This also makes it much easier to test.
@Robin5605 Robin5605 requested review from a team as code owners April 6, 2024 06:45
detail = "Dragonfly Reporter service failed"
log.error(detail, status=err.response.status_code, message=err.response.text)
raise HTTPException(502, detail=detail)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines +223 to +225
try:
response.raise_for_status()
except httpx.HTTPStatusError as err:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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))
Copy link
Contributor

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:
Copy link
Contributor

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.

@shenanigansd shenanigansd marked this pull request as draft May 30, 2024 01:09
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