Files
karaoke-gen/backend/exceptions.py
T
Andrew Beveridge ☄️andClaude Opus 4.6 04950345bc Remove legacy per-user job rate limiting (#475)
@coderabbitai ignore

## Summary
- Remove the "5 jobs per day" per-user rate limiting system, which is no
longer needed since credits now control usage
- Delete `rate_limit_service.py` and all associated tests
- Remove `RateLimitExceededError` exception and all references across
backend routes
- Remove rate limit config fields (`enable_rate_limiting`,
`rate_limit_jobs_per_day`)
- Clean up frontend admin page: remove Overview tab (rate limit stats)
and User Overrides tab
- Keep all blocklist management (domain/email/IP blocking) and YouTube
queue features intact
- Update API and README docs to reflect the change

## Changes
- **3 files deleted**: `rate_limit_service.py`,
`test_rate_limit_service.py`, `test_rate_limits_api.py`
- **13 files edited** across backend and frontend
- **Net**: ~56 insertions, ~2,465 deletions

## Test plan
- [x] All backend tests pass (1086 core + unit tests)
- [x] All frontend tests pass (176 tests)
- [x] Verified no remaining references to `RateLimitExceededError` or
`rate_limit_service`
- [x] Blocklist endpoints preserved and tested
- [x] YouTube queue endpoints preserved and tested
- [x] Credit enforcement tests updated (removed rate limit fixtures)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 14:41:18 -05:00

95 lines
2.7 KiB
Python

"""
Custom exceptions for the karaoke generation backend.
These exceptions are used for structured error handling across the application,
particularly for validation errors and credit checks.
"""
class EmailValidationError(Exception):
"""
Raised when email validation fails.
Attributes:
message: Human-readable error message
reason: Specific reason for failure (e.g., "disposable", "blocked", "invalid")
"""
def __init__(self, message: str, reason: str = "invalid"):
self.message = message
self.reason = reason
super().__init__(message)
class IPBlockedError(Exception):
"""
Raised when a request comes from a blocked IP address.
Attributes:
message: Human-readable error message
ip_address: The blocked IP address (may be partially masked)
"""
def __init__(self, message: str, ip_address: str = ""):
self.message = message
self.ip_address = ip_address
super().__init__(message)
class InsufficientCreditsError(Exception):
"""
Raised when a user attempts to create a job without sufficient credits.
Attributes:
message: Human-readable error message
credits_available: Number of credits the user currently has
credits_required: Number of credits required (always 1 for now)
"""
def __init__(
self,
message: str,
credits_available: int = 0,
credits_required: int = 1
):
self.message = message
self.credits_available = credits_available
self.credits_required = credits_required
super().__init__(message)
class InvalidStateTransitionError(Exception):
"""
Raised when an invalid job state transition is attempted.
This exception is raised by JobManager.transition_to_state() when the
requested transition is not allowed by the state machine defined in
STATE_TRANSITIONS.
Example: Trying to transition from PENDING to GENERATING_SCREENS is invalid
because PENDING can only transition to DOWNLOADING, SEARCHING_AUDIO, FAILED,
or CANCELLED.
Attributes:
message: Human-readable error message
job_id: The job ID that failed to transition
from_status: Current status of the job
to_status: Attempted target status
valid_transitions: List of valid transitions from current status
"""
def __init__(
self,
message: str,
job_id: str = "",
from_status: str = "",
to_status: str = "",
valid_transitions: list = None
):
self.message = message
self.job_id = job_id
self.from_status = from_status
self.to_status = to_status
self.valid_transitions = valid_transitions or []
super().__init__(message)