Coverage for api/exceptions.py: 70%
40 statements
« prev ^ index » next coverage.py v7.6.2, created at 2024-10-10 03:02 +0300
« prev ^ index » next coverage.py v7.6.2, created at 2024-10-10 03:02 +0300
1from starlette import status
2from starlette.exceptions import HTTPException
5class BaseSotransError(Exception):
6 pass
9class StopsLimitedInfo(BaseSotransError):
10 def __str__(self):
11 return "Not enough information on stops to calculate distance."
14class GeoAPIStatusException(BaseSotransError):
15 def __str__(self):
16 return "Geo API unexpected response."
19class GeoAPINoResults(BaseSotransError):
20 def __str__(self):
21 return "Geo API returned no results"
24class UnexpectedUserRoleError(BaseSotransError):
25 def __str__(self):
26 return "You cannot set minio policy because of unsuitable roles. Check MinioPolicySetter."
29class BadParameterHTTPError(HTTPException):
30 def __init__(self, param_name: str = "?"):
31 super().__init__(
32 status.HTTP_400_BAD_REQUEST,
33 f"Получен некорректный параметр: <{param_name}>",
34 )
37class NoAccessHTTPError(HTTPException):
38 def __init__(self, resource_name: str = "?"):
39 super().__init__(
40 status.HTTP_403_FORBIDDEN,
41 f"Нет доступа к ресурсу: <{resource_name}>",
42 )
45class NotFoundHTTPError(HTTPException):
46 def __init__(self, resource_name: str = "?"):
47 super().__init__(
48 status.HTTP_404_NOT_FOUND,
49 f"Сущность не найдена: <{resource_name}>."
50 f" Возможно, у Вас нет доступа или ключевые параметры не соответствуют.",
51 )
54class NotAcceptableHTTPError(HTTPException):
55 def __init__(self, reason: str = "?"):
56 super().__init__(
57 status.HTTP_406_NOT_ACCEPTABLE,
58 f"Не может быть принято: <{reason}>",
59 )
62class INNNotFound(BaseSotransError):
63 def __str__(self):
64 return """No data in DaData API for requested inn."""
67class SubsidiaryIsNotAssigned(BaseSotransError):
68 def __str__(self):
69 return """У пользователя не указано подразделение в профиле"""
72class DocGenerationFailed(BaseSotransError):
73 def __str__(self):
74 return """Doc service didn't return the filepath"""
77class APIKeyGenerationFailed(BaseSotransError):
78 def __str__(self):
79 return """Key generation failed."""