def process_request(self, req, resp): """ Processes the request before routing it and starts a database transaction. :param req: The request :type req: falcon.Request :param resp: The response :type resp: falcon.Response """ AbstractDAO.begin()
def handle_exception(ex, req, resp, params): """ Handles all exceptions within the application. :param ex: The exception being thrown :type ex: Exception :param req: The request :type req: falcon.Request :param resp: The response :type resp: falcon.Response :param params: The parameters of the exception :type params: dict """ assert isinstance(ex, Exception) assert isinstance(req, falcon.Request) assert isinstance(resp, falcon.Response) assert isinstance(params, dict) __LOGGER.exception(str(ex)) try: AbstractDAO.rollback() except Exception as _ex: __LOGGER.exception(str(_ex)) ex = _ex if isinstance(ex, falcon.HTTPError) is False: error_str = str(ex) if not error_str: error_str = "An Error Has Occurred" raise falcon.HTTPError( status=falcon.status_codes.HTTP_500, title=falcon.status_codes.HTTP_500, description=error_str, code=9999 ) elif isinstance(ex, falcon.HTTPNotFound): raise falcon.HTTPError( status=falcon.status_codes.HTTP_404, title=falcon.status_codes.HTTP_404, description="Resource Not Found", code=9998 ) else: raise
def process_response(self, req, resp, resource): """ Post-processing of the response (after routing). :param req: The request :type req: falcon.Request :param resp: The response :type resp: falcon.Response """ if resp.status in DAOTransaction.__OK_STATUSES: AbstractDAO.commit() else: assert resp.status not in DAOTransaction.__OK_STATUSES AbstractDAO.rollback() # close the session close_db_connection()
def run(self): """ Sets up the application, runs the command, and then tears everything down """ system.initialize() try: RemoteCommand.__LOGGER.debug("Starting remote command: %s", self.__command.command_key) AbstractDAO.begin() self.__command.run() AbstractDAO.commit() RemoteCommand.__LOGGER.debug("Finished remote command: %s", self.__command.command_key) except Exception: RemoteCommand.__LOGGER.exception("Error while running remote command: %s", self.__command.command_key) AbstractDAO.rollback() finally: system.dispose()
def run(self): print AbstractDAO.get_session() raise Exception("BOOOOM")