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
No related branches found
No related tags found
No related merge requests found
......@@ -3,12 +3,13 @@ from typing import Iterable
from videoag_common.miscellaneous.util import JsonTypes
from .constants import *
from .errors import (
ApiClientException,
ERROR_REQUEST_INVALID_PARAMETER,
ERROR_REQUEST_MISSING_PARAMETER
)
class CJsonException(Exception):
def __init__(self, path: str, message: str):
super().__init__(f"At {path}: {message}")
self.path = path
self.message = message
class CJsonValue:
......@@ -18,7 +19,7 @@ class CJsonValue:
self._path = path
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):
return self._data == json
......@@ -39,7 +40,7 @@ class CJsonValue:
return self._data
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:
self.__check_value_type(int, "int")
......@@ -88,7 +89,7 @@ class CJsonObject(CJsonValue):
if optional and not self.has(key):
return None
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}")
def get_object(self, key: str) -> "CJsonObject":
......@@ -148,7 +149,7 @@ class CJsonArray(CJsonValue, Iterable[CJsonValue]):
if index < 0:
raise ValueError(f"Negative index provided: {index}") # pragma: no cover
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}]")
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