Remnawave_python-sdk/remnawave_api/exceptions/general.py
Artem f47cda9378
feat: Add models for subscriptions, users, and system statistics
- Implemented TemplateResponseDto and UpdateTemplateRequestDto for subscription templates.
- Created models for system statistics including CPU, memory, and bandwidth.
- Developed user models for user creation, updates, and responses.
- Added bulk actions for user updates and statistics tracking.
- Introduced tests for authentication, bandwidth statistics, hosts, inbounds, key generation, nodes, subscriptions, and user management.
- Enhanced utility functions for generating random strings, emails, and date ranges for testing.
2025-04-21 20:44:27 +02:00

61 lines
1.4 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_api.enums import ErrorCode
class ApiErrorResponse(BaseModel):
timestamp: datetime = Field(..., description="Время возникновения ошибки")
path: str = Field(..., description="Путь запроса")
message: str = Field(..., description="Сообщение об ошибке")
code: ErrorCode | str = Field(
...,
validation_alias=AliasChoices("errorCode", "code", "error_code"),
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