Remnawave_python-sdk/remnawave/exceptions/general.py
Artem 950a7ffab3
Add Pydantic models for nodes usage history, subscriptions, and user management
- 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.
2025-07-03 12:22:16 +02:00

67 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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