I don't think this is an appropriate solution. First of all, the error reporting does not work. You call `jsonify` to create an error rrsponse but it is never returned. If you have to return it then the contextmanager would have to return a tuple with `(error, invitation, user)` which does not seem to be the right thing. Context managers were not really intended for this kind of code.

I would prefer to simply see  `load_invite` and `validate_invite` functions that return an error if the invite is bad.