error_handling.py 524 B

12345678910111213141516
  1. from functools import wraps
  2. from ..types import Message, Context, Response, CommandType
  3. from ..failure import RollbotFailureException
  4. def with_failure_handling(fn: CommandType) -> CommandType:
  5. @wraps(fn)
  6. async def wrapped(message: Message, context: Context):
  7. try:
  8. await fn(message, context)
  9. except RollbotFailureException as exc:
  10. # TODO handle errors more specifically
  11. await context.respond(Response.from_message(message, str(exc.failure)))
  12. return wrapped