From 7fc2b83f53ba5d542fca745db487832c9a31c1f7 Mon Sep 17 00:00:00 2001 From: shoulinwei Date: Thu, 15 Apr 2021 10:36:31 +0800 Subject: [PATCH] error --- csst_dfs_commons/models/__init__.py | 28 +++++++++++++++++++--------- csst_dfs_commons/models/errors.py | 8 ++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 csst_dfs_commons/models/errors.py diff --git a/csst_dfs_commons/models/__init__.py b/csst_dfs_commons/models/__init__.py index b11efb7..c3f7031 100644 --- a/csst_dfs_commons/models/__init__.py +++ b/csst_dfs_commons/models/__init__.py @@ -2,28 +2,38 @@ class Result(dict): def __init__(self): super(Result, self).__init__() - self.code = 0 - self.message = "" - self.data = None + self["code"] = 0 + self["message"] = "" + self["data"] = None def success(self): - return self.code >= 0 + return self["code"] >= 0 + def data(self): + return self["data"] + + def message(self): + return self["message"] + @staticmethod def error(code = -1, message = ""): r = Result() - r.code = code - r.message = message + r["code"] = code + r["message"] = message return r @staticmethod def ok_data(data): r = Result() - r.data = data + r["data"] = data return r @staticmethod def ok_msg(message): r = Result() - r.message = message - return r \ No newline at end of file + r["message"] = message + return r + + def append(self, k: str, v): + self[k] = v + return self \ No newline at end of file diff --git a/csst_dfs_commons/models/errors.py b/csst_dfs_commons/models/errors.py new file mode 100644 index 0000000..9134aa2 --- /dev/null +++ b/csst_dfs_commons/models/errors.py @@ -0,0 +1,8 @@ + +class CSSTGenericException(Exception): + def __init__(self, *args) -> None: + super(CSSTGenericException, self).__init__(*args) + +class CSSTFatalException(Exception): + def __init__(self, *args) -> None: + super(CSSTFatalException, self).__init__(*args) \ No newline at end of file -- GitLab