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

Raise HTTPExceptions rather than returning #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions ddapm_test_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async def handle_exception_middleware(request: Request, handler: _Handler) -> we
except HTTPException:
raise
except Exception as e:
return web.HTTPBadRequest(reason=str(e))
raise web.HTTPBadRequest(reason=str(e))


async def _forward_request(request_data: bytes, headers: Mapping[str, str], full_agent_url: str) -> ClientResponse:
Expand Down Expand Up @@ -297,13 +297,13 @@ async def get_trace_check_failures(self, request: Request) -> web.Response:
for check_trace, failure_message in trace_check_failures:
results = check_trace.get_failures_by_check(results)
json_summary = json.dumps(results)
return web.HTTPBadRequest(body=json_summary, content_type="application/json")
raise web.HTTPBadRequest(body=json_summary, content_type="application/json")
else:
# or use default response of text
msg = f"APM Test Agent Validation failed with {n_failures} Trace Check failures.\n"
for check_trace, failure_message in trace_check_failures:
msg += failure_message
return web.HTTPBadRequest(text=msg)
raise web.HTTPBadRequest(text=msg)
else:
return web.HTTPOk()

Expand Down Expand Up @@ -588,7 +588,7 @@ async def handle_v1_tracer_flare(self, request: Request) -> web.Response:
if "error" in tracer_flare:
msg = f"Error while parsing flare request: {tracer_flare['error']}"
log.error(msg)
return web.HTTPBadRequest(text=msg)
raise web.HTTPBadRequest(text=msg)

expectedFields = ["source", "case_id", "email", "hostname", "flare_file"]
missingFields = [k for k in expectedFields if k not in tracer_flare]
Expand All @@ -598,7 +598,7 @@ async def handle_v1_tracer_flare(self, request: Request) -> web.Response:
else:
msg = f"Flare request is missing {','.join(missingFields)}"
log.error(msg)
return web.HTTPBadRequest(text=msg)
raise web.HTTPBadRequest(text=msg)

async def handle_put_tested_integrations(self, request: Request) -> web.Response:
# we need to store the request manually since this is not a real DD agent endpoint
Expand Down Expand Up @@ -838,7 +838,7 @@ async def handle_session_traces(self, request: Request) -> web.Response:
try:
traces = await self._traces_by_session(token)
except NoSuchSessionException as e:
return web.HTTPNotFound(reason=str(e))
raise web.HTTPNotFound(reason=str(e))

return web.json_response(traces)

Expand Down Expand Up @@ -1038,7 +1038,7 @@ async def check_failure_middleware(self, request: Request, handler: _Handler) ->
# append failure to trace failures
self._trace_failures[token].append((trace, msg))
log.error(msg)
return web.HTTPBadRequest(body=msg)
raise web.HTTPBadRequest(body=msg)
else:
token = request["session_token"]
# update trace_check results
Expand All @@ -1057,7 +1057,7 @@ async def check_failure_middleware(self, request: Request, handler: _Handler) ->
log.error(msg)
if request.app["disable_error_responses"]:
return response
return web.HTTPBadRequest(body=msg)
raise web.HTTPBadRequest(body=msg)
return response


Expand Down
Loading