Error page
This commit is contained in:
parent
baf6b15e17
commit
73939a8e2f
3 changed files with 59 additions and 4 deletions
|
@ -28,6 +28,7 @@ THUMB_URL = "https://images.make.fangam.es"
|
||||||
# \S[A-Z0-9]{8} = without dash, no whitespace
|
# \S[A-Z0-9]{8} = without dash, no whitespace
|
||||||
level_code_regex = re.compile("[A-Z0-9]{4}\-[A-Z0-9]{4}|[A-Z0-9]{8}")
|
level_code_regex = re.compile("[A-Z0-9]{4}\-[A-Z0-9]{4}|[A-Z0-9]{8}")
|
||||||
|
|
||||||
|
error_template = template_env.get_template("error.html")
|
||||||
@app.get("/", response_class=HTMLResponse)
|
@app.get("/", response_class=HTMLResponse)
|
||||||
async def root():
|
async def root():
|
||||||
template = template_env.get_template("home.html")
|
template = template_env.get_template("home.html")
|
||||||
|
@ -96,11 +97,16 @@ async def search(
|
||||||
"name": search,
|
"name": search,
|
||||||
**last_x_hours, **author
|
**last_x_hours, **author
|
||||||
}, timeout=10)
|
}, timeout=10)
|
||||||
|
if rq.status_code == 503:
|
||||||
|
return error_template.render(reason="Server is unavailable right now.")
|
||||||
searchResults = rq.json()
|
searchResults = rq.json()
|
||||||
print(rq.url, p * limit)
|
print(rq.url, p * limit)
|
||||||
except httpx.ReadTimeout:
|
except httpx.ReadTimeout:
|
||||||
return "Server timed out"
|
return error_template.render(reason="Server timed out")
|
||||||
|
except json.decoder.JSONDecodeError:
|
||||||
|
return error_template.render(reason="Failed to parse server response.", details=rq.text)
|
||||||
|
except Exception as exc:
|
||||||
|
return error_template.render(reason="Uncaught exception", details=exc)
|
||||||
entryNumber=len(searchResults)
|
entryNumber=len(searchResults)
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,10 +129,16 @@ async def showLevel(level_id: int):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rq = httpx.get(BASE_URL + "/api/v1/map/" + str(level_id), timeout=10)
|
rq = httpx.get(BASE_URL + "/api/v1/map/" + str(level_id), timeout=10)
|
||||||
|
if rq.status_code == 503:
|
||||||
|
return error_template.render(reason="Server is unavailable right now")
|
||||||
searchResults = rq.json()
|
searchResults = rq.json()
|
||||||
print(rq.url)
|
print(rq.url)
|
||||||
except httpx.ReadTimeout:
|
except httpx.ReadTimeout:
|
||||||
return "Server timed out"
|
return error_template.render(reason="Server timed out")
|
||||||
|
except json.decoder.JSONDecodeError:
|
||||||
|
return error_template.render(reason="Failed to parse server response.", details=rq.text)
|
||||||
|
except Exception as exc:
|
||||||
|
return error_template.render(reason="Uncaught exception", details=exc)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -141,10 +153,16 @@ async def showUser(user_id: int):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rq = httpx.get(BASE_URL + "/api/v1/user/" + str(user_id), timeout=10)
|
rq = httpx.get(BASE_URL + "/api/v1/user/" + str(user_id), timeout=10)
|
||||||
|
if status_code == 503:
|
||||||
|
return error_template.render(reason="Server is unavailable right now")
|
||||||
searchResults = rq.json()
|
searchResults = rq.json()
|
||||||
print(rq.url)
|
print(rq.url)
|
||||||
except httpx.ReadTimeout:
|
except httpx.ReadTimeout:
|
||||||
return "Server timed out"
|
return error_template.render(reason="Server timed out")
|
||||||
|
except json.decoder.JSONDecodeError:
|
||||||
|
return error_template.render(reason="Failed to parse server response.", details=rq.text)
|
||||||
|
except Exception as exc:
|
||||||
|
return error_template.render(reason="Uncaught exception", details=exc)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
11
iwm_browser/static/error.css
Normal file
11
iwm_browser/static/error.css
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
body {
|
||||||
|
font-size: medium;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: large;
|
||||||
|
}
|
||||||
|
|
||||||
|
details * {
|
||||||
|
font-size: small;
|
||||||
|
}
|
26
iwm_browser/templates/error.html
Normal file
26
iwm_browser/templates/error.html
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title></title>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="stylesheet" href="/static/index.css">
|
||||||
|
<link rel="stylesheet" href="/static/main.css">
|
||||||
|
<link rel="stylesheet" href="/static/error.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="Home">
|
||||||
|
<div class="contentBox">
|
||||||
|
<div class="header">Something went wrong</div>
|
||||||
|
<div class="splitter" />
|
||||||
|
<h1>{{ reason }}</h1>
|
||||||
|
{% if details %}
|
||||||
|
<details>
|
||||||
|
<summary>More details</summary>
|
||||||
|
<pre>{{ details }}</pre>
|
||||||
|
</details>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue