示例#1
0
文件: handler.py 项目: ppcult/edmunds
    def render(self, exception):
        """
        Render the exception
        :param exception:   The exception
        :type  exception:   Exception
        :return:            The response
        """

        if not isinstance(exception, HTTPException):
            http_exception = InternalServerError()
        else:
            http_exception = exception
        is_server_error = http_exception.code - (http_exception.code %
                                                 100) == 500

        if self.app.debug and is_server_error:
            if sys.version_info < (3, 0):
                exc_type, exc_value, tb = sys.exc_info()
                if exc_value is exception:
                    reraise(exc_type, exc_value, tb)
            raise exception
        else:
            if self.app.testing and is_server_error and isinstance(
                    exception, Exception):
                http_exception.description = '%s' % exception
            return http_exception.get_response()
示例#2
0
 def get_tree_by_id(id):
     """
     Returns the tree corresponding to the ID else an error status that
     the client must handle.
     """
     try:
         tree = db_interface.get_tree_by_id(int(id))
         return jsonify(tree)
     except KeyError as e:
         nf = NotFound()
         nf.description = str(e)
         raise nf
     except Exception as e:
         internalSrvErr = InternalServerError()
         internalSrvErr.description = str(e)
         raise internalSrvErr