diff --git a/iwm_browser/main.py b/iwm_browser/main.py index 1d893b6..3e06141 100644 --- a/iwm_browser/main.py +++ b/iwm_browser/main.py @@ -28,6 +28,7 @@ THUMB_URL = "https://images.make.fangam.es" # \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}") +error_template = template_env.get_template("error.html") @app.get("/", response_class=HTMLResponse) async def root(): template = template_env.get_template("home.html") @@ -96,11 +97,16 @@ async def search( "name": search, **last_x_hours, **author }, timeout=10) + if rq.status_code == 503: + return error_template.render(reason="Server is unavailable right now.") searchResults = rq.json() print(rq.url, p * limit) 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) @@ -123,10 +129,16 @@ async def showLevel(level_id: int): try: 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() print(rq.url) 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: 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() print(rq.url) 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) diff --git a/iwm_browser/static/error.css b/iwm_browser/static/error.css new file mode 100644 index 0000000..1ee29d0 --- /dev/null +++ b/iwm_browser/static/error.css @@ -0,0 +1,11 @@ +body { + font-size: medium; +} + +h1 { + font-size: large; +} + +details * { + font-size: small; +} diff --git a/iwm_browser/static/homepage.css b/iwm_browser/static/homepage.css index 9052ddb..86b1832 100644 --- a/iwm_browser/static/homepage.css +++ b/iwm_browser/static/homepage.css @@ -1,26 +1,3 @@ -/* .Home { - display: flex; - justify-content: center; - align-items: center; - - width: 100%; - height: 100%; -} - -.contentBox { - display: flex; - flex-direction: column; - align-items: center; - text-align: center; - - outline: 2px solid whitesmoke; - padding: 16px; - - /* width: 80%; */ - /* height: 80%; */ - -} */ - .tileBox { display: flex; /* outline: 3px dashed pink; */ @@ -59,4 +36,25 @@ .homeTile a:hover { color: cyan; -} \ No newline at end of file +} + +.Home { + font-size: larger; +} + +a:link, a:visited { + color: inherit; + text-decoration: initial; + cursor: auto; +} + +a:hover { + outline: 2px dotted blue; +} + +a:link:active { + color: inherit; + outline: 2px dotted blue; +} + + diff --git a/iwm_browser/static/index.css b/iwm_browser/static/index.css index 8698e2a..e9bc3cb 100644 --- a/iwm_browser/static/index.css +++ b/iwm_browser/static/index.css @@ -13,7 +13,7 @@ body { background-color: #20202a; color: #eee; - font-size: xx-large; + font-size: large; font-family: monospace; } diff --git a/iwm_browser/static/search/search.css b/iwm_browser/static/search/search.css index 250fdaf..d2f433e 100644 --- a/iwm_browser/static/search/search.css +++ b/iwm_browser/static/search/search.css @@ -4,6 +4,7 @@ } .header { + font-size: medium; text-align: center; height: min-content; } @@ -29,7 +30,7 @@ border-right: 1px dotted white; font-family: monospace; - font-size: 0.5em; + font-size: medium; } .searchBar .searchButton { diff --git a/iwm_browser/templates/error.html b/iwm_browser/templates/error.html new file mode 100644 index 0000000..9776f8c --- /dev/null +++ b/iwm_browser/templates/error.html @@ -0,0 +1,26 @@ + + +
+{{ details }}+