Spaces:
Running
Running
File size: 1,710 Bytes
9fe5a30 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
"""Custom exception classes for the multi-utility server."""
from typing import Optional
class MultiUtilityServerException(Exception):
"""Base exception class for the multi-utility server."""
def __init__(self, message: str, status_code: int = 500) -> None:
self.message = message
self.status_code = status_code
super().__init__(self.message)
class AuthenticationError(MultiUtilityServerException):
"""Raised when API key authentication fails."""
def __init__(self, message: str = "Invalid or missing API key") -> None:
super().__init__(message, status_code=401)
class InvalidVideoURLError(MultiUtilityServerException):
"""Raised when the provided video URL is invalid."""
def __init__(self, message: str = "Invalid YouTube URL or missing parameters") -> None:
super().__init__(message, status_code=400)
class SubtitlesNotFoundError(MultiUtilityServerException):
"""Raised when no subtitles are available for the requested language."""
def __init__(self, message: str = "No subtitles available in the requested language") -> None:
super().__init__(message, status_code=404)
class DownloadTimeoutError(MultiUtilityServerException):
"""Raised when yt-dlp operations timeout."""
def __init__(self, message: str = "Subtitle extraction timed out") -> None:
super().__init__(message, status_code=408)
class SubtitleExtractionError(MultiUtilityServerException):
"""Raised when subtitle extraction fails due to yt-dlp error."""
def __init__(self, message: str = "Subtitle extraction failed due to yt-dlp error") -> None:
super().__init__(message, status_code=500) |