Skip to content
Snippets Groups Projects
Commit d99a61e5 authored by Simon Künzel's avatar Simon Künzel
Browse files

Use new CJsonException instead of ApiClientException

parent 71a13882
Branches
No related tags found
No related merge requests found
...@@ -3,12 +3,13 @@ from typing import Iterable ...@@ -3,12 +3,13 @@ from typing import Iterable
from videoag_common.miscellaneous.util import JsonTypes from videoag_common.miscellaneous.util import JsonTypes
from .constants import *
from .errors import ( class CJsonException(Exception):
ApiClientException,
ERROR_REQUEST_INVALID_PARAMETER, def __init__(self, path: str, message: str):
ERROR_REQUEST_MISSING_PARAMETER super().__init__(f"At {path}: {message}")
) self.path = path
self.message = message
class CJsonValue: class CJsonValue:
...@@ -18,7 +19,7 @@ class CJsonValue: ...@@ -18,7 +19,7 @@ class CJsonValue:
self._path = path self._path = path
def raise_error(self, message: str): def raise_error(self, message: str):
raise ApiClientException(ERROR_REQUEST_INVALID_PARAMETER(self._path, message)) raise CJsonException(self._path, message)
def equals_json(self, json: JsonTypes): def equals_json(self, json: JsonTypes):
return self._data == json return self._data == json
...@@ -39,7 +40,7 @@ class CJsonValue: ...@@ -39,7 +40,7 @@ class CJsonValue:
return self._data return self._data
def as_sint32(self) -> int: def as_sint32(self) -> int:
return self.as_int(MIN_VALUE_SINT32, MAX_VALUE_SINT32) return self.as_int(-2147483648, 2147483647)
def as_int(self, min_value: int, max_value: int) -> int: def as_int(self, min_value: int, max_value: int) -> int:
self.__check_value_type(int, "int") self.__check_value_type(int, "int")
...@@ -88,7 +89,7 @@ class CJsonObject(CJsonValue): ...@@ -88,7 +89,7 @@ class CJsonObject(CJsonValue):
if optional and not self.has(key): if optional and not self.has(key):
return None return None
if key not in self._data: if key not in self._data:
raise ApiClientException(ERROR_REQUEST_MISSING_PARAMETER(f"{self._path}.{key}")) raise CJsonException(f"{self._path}.{key}", "Is missing")
return CJsonValue(self._data[key], f"{self._path}.{key}") return CJsonValue(self._data[key], f"{self._path}.{key}")
def get_object(self, key: str) -> "CJsonObject": def get_object(self, key: str) -> "CJsonObject":
...@@ -148,7 +149,7 @@ class CJsonArray(CJsonValue, Iterable[CJsonValue]): ...@@ -148,7 +149,7 @@ class CJsonArray(CJsonValue, Iterable[CJsonValue]):
if index < 0: if index < 0:
raise ValueError(f"Negative index provided: {index}") # pragma: no cover raise ValueError(f"Negative index provided: {index}") # pragma: no cover
if index >= self.length(): if index >= self.length():
raise ApiClientException(ERROR_REQUEST_MISSING_PARAMETER(f"{self._path}[{index}]")) raise CJsonException(f"{self._path}[{index}]", "Is missing")
return CJsonValue(self._data[index], f"{self._path}[{index}]") return CJsonValue(self._data[index], f"{self._path}[{index}]")
def get_object(self, index: int) -> "CJsonObject": def get_object(self, index: int) -> "CJsonObject":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment