async def new_func(self: View, **kwargs): """Checks the given request against the supplied permission and gracefully fails.""" try: await permission(self, **kwargs) except RoutePermissionError as error: response_schema = JSendSchema() return web.json_response(response_schema.dump({ "status": JSendStatus.FAIL, "data": { "message": f"You cannot do that because because {str(error)}.", "reasons": error.serialize() } }), status=HTTPStatus.UNAUTHORIZED) except Exception as error: raise type(error)(original_function, *error.args) from error return await original_function(self, **kwargs)
async def _me_handler(self): """ Accepts all types of request, does some checking against the user, and forwards them on to the appropriate user. """ user = await get_user(firebase_id=self.request["token"]) if user is None: response_schema = JSendSchema() create_user_url = str(self.request.app.router['users'].url_for()) return web.json_response(response_schema.dump({ "status": JSendStatus.FAIL, "data": { "message": "User does not exist. Please use your jwt to create a user and try again.", "url": create_user_url, "method": "POST" } }), status=HTTPStatus.BAD_REQUEST) concrete_url = MeView._get_concrete_user_url( self.request.path, self.request.match_info.get("tail"), user) raise web.HTTPTemporaryRedirect(concrete_url)