Source code for sidecar.web_decorator

import asyncio
import logging
import traceback

from aiohttp import web

log = logging.getLogger(__name__)

# TODO(dmankin): figure out if we can replace this by a middleware
[docs]def unhandled_exception_500(wrapped): """Decorator of a coroutine that returns a 500 error containing the stack trace of any unhandled exception.""" @asyncio.coroutine def inner(*args): try: return (yield from wrapped(*args)) except Exception: log.exception("Unhandled exception processing %s()", wrapped.__name__) return web.Response(status=500, text="Unhandled exception\n" + "".join(traceback.format_exc())) return inner