feat(api): Add rate-limiting error message

This commit is contained in:
AaronBenDaniel
2024-11-09 14:39:21 -05:00
parent d58a119c10
commit fa1bac3045
+8
View File
@@ -16,6 +16,7 @@ from create_book import (
import tempfile
from io import BytesIO
from fastapi.staticfiles import StaticFiles
from aiohttp import ClientResponseError
app = FastAPI()
BUILD_PATH = Path(__file__).parent / "build"
@@ -107,6 +108,13 @@ async def handle_download(
content='The story you tried to download does not exist or has been deleted. Support is available on the <a href="https://discord.gg/P9RHC4KCwd" target="_blank">Discord</a>',
)
except ClientResponseError:
# Rate-limit by Wattpad
return HTMLResponse(
status_code=429,
content='Unfortunately, the downloader got rate-limited by Wattpad. Please try again later. Support is available on the <a href="https://discord.gg/P9RHC4KCwd" target="_blank">Discord</a>',
)
app.mount("/", StaticFiles(directory=BUILD_PATH), "static")