summaryrefslogtreecommitdiff
path: root/py_include/homekit/api/errors/api_response_error.py
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-06-10 23:02:34 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-06-10 23:02:34 +0300
commitb0bf43e6a272d42a55158e657bd937cb82fc3d8d (patch)
treef1bc13253bc028abcaed9c88882f5aee384a269c /py_include/homekit/api/errors/api_response_error.py
parentf3b9d50496257d87757802dfb472b5ffae11962c (diff)
move files, rename home package to homekit
Diffstat (limited to 'py_include/homekit/api/errors/api_response_error.py')
-rw-r--r--py_include/homekit/api/errors/api_response_error.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/py_include/homekit/api/errors/api_response_error.py b/py_include/homekit/api/errors/api_response_error.py
new file mode 100644
index 0000000..85d788b
--- /dev/null
+++ b/py_include/homekit/api/errors/api_response_error.py
@@ -0,0 +1,28 @@
+from typing import Optional, List
+
+
+class ApiResponseError(Exception):
+ def __init__(self,
+ status_code: int,
+ error_type: str,
+ error_message: str,
+ error_stacktrace: Optional[List[str]] = None):
+ super().__init__()
+ self.status_code = status_code
+ self.error_message = error_message
+ self.error_type = error_type
+ self.error_stacktrace = error_stacktrace
+
+ def __str__(self):
+ def st_formatter(line: str):
+ return f'Remote| {line}'
+
+ s = f'{self.error_type}: {self.error_message} (HTTP {self.status_code})'
+ if self.error_stacktrace is not None:
+ st = []
+ for st_line in self.error_stacktrace:
+ st.append('\n'.join(st_formatter(st_subline) for st_subline in st_line.split('\n')))
+ s += '\nRemote stacktrace:\n'
+ s += '\n'.join(st)
+
+ return s