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

(chore): add error string to handle_snapshot #163

Merged
merged 6 commits into from
Feb 12, 2024
Merged
Changes from 4 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
14 changes: 14 additions & 0 deletions ddapm_test_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from aiohttp import web
from aiohttp.web import Request
from aiohttp.web import middleware
from aiohttp.web import HTTPException
from msgpack.exceptions import ExtraData as MsgPackExtraDataException
from multidict import CIMultiDict

Expand Down Expand Up @@ -107,6 +108,18 @@ async def session_token_middleware(request: Request, handler: _Handler) -> web.R
return await handler(request)


@middleware
async def handle_exception_middleware(request: Request, handler: _Handler) -> web.Response:
"""Turn exceptions into 400s with the reason from the exception."""
try:
response = await handler(request)
return response
except HTTPException:
raise
except Exception as e:
return web.HTTPBadRequest(reason=str(e))


async def _forward_request(request_data: bytes, headers: Mapping[str, str], full_agent_url: str) -> ClientResponse:
async with ClientSession() as session:
async with session.post(
Expand Down Expand Up @@ -1035,6 +1048,7 @@ def make_app(
app = web.Application(
client_max_size=int(100e6), # 100MB - arbitrary
middlewares=[
handle_exception_middleware, #type: ignore
agent.check_failure_middleware, # type: ignore
agent.store_request_middleware, # type: ignore
agent.request_forwarder_middleware, # type: ignore
Expand Down
Loading