from functools import wraps from ..types import Message, Context, Response, CommandType from ..failure import RollbotFailureException def with_failure_handling(fn: CommandType) -> CommandType: @wraps(fn) async def wrapped(message: Message, context: Context): try: await fn(message, context) except RollbotFailureException as exc: # TODO handle errors more specifically await context.respond(Response.from_message(message, str(exc.failure))) return wrapped