Skip to content

Instantly share code, notes, and snippets.

@yuvalherziger
Last active January 11, 2022 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuvalherziger/612afa690ace7b12446625922677cad5 to your computer and use it in GitHub Desktop.
Save yuvalherziger/612afa690ace7b12446625922677cad5 to your computer and use it in GitHub Desktop.
awaitables.py
from aiohttp.web import Request
from aiohttp_catcher import catch, Catcher
async def message(exc: MyException, request: Request):
return "This isn't allowed"
async def fields(exc: MyException, req: Request):
return {
"method": req.method,
"error_type": exc.some_error_class_attribute
}
async def main():
# ...
catcher = Catcher()
await catcher.add_scenarios(
catch(MyException).with_status_code(401).and_call(message).with_additional_fields(fields),
)
#...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment