feat: 美化错误页面

This commit is contained in:
2025-12-17 12:31:16 +08:00
parent 5fdd986a63
commit 27e9a74e4e

60
app.py
View File

@@ -32,7 +32,65 @@ THEMES = {
def hello():
# 模拟 v3.0-buggy 的问题
if BUGGY and random.random() < 0.5:
return "💥 服务异常:数据库连接失败", 500
return (
f"""
<!DOCTYPE html>
<html>
<head>
<title>服务异常</title>
<meta charset="utf-8">
<meta http-equiv="refresh" content="3">
<style>
body {{
font-family: Arial;
max-width: 700px;
margin: 50px auto;
padding: 30px;
background: linear-gradient(135deg, #E74C3C22 0%, #E74C3C44 100%);
}}
.error-box {{
background: white;
padding: 40px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
text-align: center;
border-left: 5px solid #E74C3C;
}}
.error-icon {{
font-size: 4em;
margin-bottom: 20px;
}}
.error-message {{
color: #E74C3C;
font-size: 1.5em;
font-weight: bold;
margin-bottom: 20px;
}}
.info {{
color: #666;
margin: 10px 0;
}}
.auto-refresh {{
color: #999;
font-size: 0.85em;
margin-top: 20px;
}}
</style>
</head>
<body>
<div class="error-box">
<div class="error-icon">💥</div>
<div class="error-message">服务异常:数据库连接失败</div>
<div class="info">版本: {VERSION}</div>
<div class="info">主机: {socket.gethostname()}</div>
<div class="info">学号: s{os.getenv("STUDENT_ID", "00")}</div>
<div class="auto-refresh">🔄 页面每3秒自动刷新</div>
</div>
</body>
</html>
""",
500,
)
theme = THEMES.get(VERSION, THEMES["v1.0"])