diff --git a/ddapm_test_agent/agent.py b/ddapm_test_agent/agent.py index a6de24a7..8cd91687 100644 --- a/ddapm_test_agent/agent.py +++ b/ddapm_test_agent/agent.py @@ -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: @@ -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() @@ -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] @@ -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 @@ -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) @@ -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 @@ -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