Changeset View
Changeset View
Standalone View
Standalone View
swh/core/api/asynchronous.py
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | |||||
async def error_middleware(app, handler): | async def error_middleware(app, handler): | ||||
async def middleware_handler(request): | async def middleware_handler(request): | ||||
try: | try: | ||||
return await handler(request) | return await handler(request) | ||||
except Exception as e: | except Exception as e: | ||||
if isinstance(e, aiohttp.web.HTTPException): | if isinstance(e, aiohttp.web.HTTPException): | ||||
raise | raise | ||||
logger.exception(e) | |||||
res = exception_to_dict(e) | res = exception_to_dict(e) | ||||
if isinstance(e, app.client_exception_classes): | if isinstance(e, app.client_exception_classes): | ||||
status = 400 | status = 400 | ||||
else: | else: | ||||
logger.exception(e) | |||||
status = 500 | status = 500 | ||||
return encode_data_server(res, status=status) | return encode_data_server(res, status=status) | ||||
return middleware_handler | return middleware_handler | ||||
class RPCServerApp(aiohttp.web.Application): | class RPCServerApp(aiohttp.web.Application): | ||||
"""For each endpoint of the given `backend_class`, tells app.route to call | """For each endpoint of the given `backend_class`, tells app.route to call | ||||
▲ Show 20 Lines • Show All 100 Lines • Show Last 20 Lines |