mirror of
https://github.com/remnawave/python-sdk.git
synced 2026-08-31 14:21:05 +00:00
- Implemented models for nodes usage history including NodeInfoDto, GetUserAccessibleNodesResponse, and usage statistics. - Created subscription-related models such as UserSubscription, SubscriptionInfoData, and various response DTOs for subscription information. - Developed models for subscription settings, templates, and system statistics, enhancing the API's capability to manage and retrieve subscription configurations. - Introduced user management models including CreateUserRequestDto, UpdateUserRequestDto, and various response DTOs for user actions. - Added bulk actions for user updates and statistics tracking, improving the efficiency of user management operations. - Established a base controller for handling API requests and responses, along with decorators for HTTP methods to streamline API interactions. - Included utility functions for serialization using orjson for better performance with Pydantic models.
67 lines
1.6 KiB
Python
67 lines
1.6 KiB
Python
from datetime import datetime
|
||
|
||
from pydantic import AliasChoices, BaseModel, Field
|
||
|
||
from remnawave.enums import ErrorCode
|
||
|
||
|
||
from typing import Any, List, Optional
|
||
|
||
|
||
class ApiErrorResponse(BaseModel):
|
||
timestamp: Optional[datetime] = Field(None, description="Время возникновения ошибки")
|
||
path: Optional[str] = Field(None, description="Путь запроса")
|
||
message: str = Field(..., description="Сообщение об ошибке")
|
||
code: Optional[ErrorCode | str] = Field(
|
||
None,
|
||
validation_alias=AliasChoices("errorCode", "code", "error_code"),
|
||
description="Код ошибки",
|
||
)
|
||
# Support for API v2 error format
|
||
status_code: Optional[int] = Field(None, alias="statusCode")
|
||
errors: Optional[List[Any]] = Field(None, description="Детали ошибок валидации")
|
||
|
||
|
||
class ApiError(Exception):
|
||
def __init__(self, status_code: int, error: ApiErrorResponse):
|
||
self.status_code = status_code
|
||
self.error = error
|
||
super().__init__(
|
||
f"API Error {error.code}: {error.message} (HTTP {status_code})"
|
||
)
|
||
|
||
|
||
class BadRequestError(ApiError):
|
||
"""Ошибки клиента (400)"""
|
||
|
||
pass
|
||
|
||
|
||
class UnauthorizedError(ApiError):
|
||
"""Ошибка авторизации (401)"""
|
||
|
||
pass
|
||
|
||
|
||
class ForbiddenError(ApiError):
|
||
"""Доступ запрещен (403)"""
|
||
|
||
pass
|
||
|
||
|
||
class NotFoundError(ApiError):
|
||
"""Ресурс не найден (404)"""
|
||
|
||
pass
|
||
|
||
|
||
class ConflictError(ApiError):
|
||
"""Конфликт (409)"""
|
||
|
||
pass
|
||
|
||
|
||
class ServerError(ApiError):
|
||
"""Серверная ошибка (500)"""
|
||
|
||
pass
|