From d65cda8eb0379447894be68e3918a2167348fe54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20N=C3=B8rgaard?= Date: Sun, 14 Apr 2024 22:20:25 +0100 Subject: [PATCH] minor fixes around missing users --- anilist-cmp/__init__.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/anilist-cmp/__init__.py b/anilist-cmp/__init__.py index 01cb516..17cdfbc 100644 --- a/anilist-cmp/__init__.py +++ b/anilist-cmp/__init__.py @@ -144,11 +144,12 @@ def _get_common_planning(data: AnilistResponse) -> dict[int, InnerMediaEntry]: def _handle_errors(errors: list[AnilistError], user1: str, user2: str) -> list[str]: missing_users: list[str] = [] for error in errors: - if error["message"] == "User not found": + if error["message"] == "User not found" and error["status"] == 404: for location in error["locations"]: - if location["column"] == 2: + print(location, flush=True) + if location["line"] == 3: missing_users.append(user1) - elif location["column"] == 17: + elif location["line"] == 18: missing_users.append(user2) return missing_users @@ -160,7 +161,7 @@ async def index() -> Response: @app.get("/{user1}/{user2}") -async def get_matches(request: Request, user1: str, user2: str, status: str = "PLANNING") -> Response: +async def get_matches(request: Request, user1: str, user2: str, status: str = "planning") -> Response: if user1.casefold() == user2.casefold(): return Response("Haha, you're really funny.", media_type="text/plain") @@ -176,7 +177,7 @@ async def get_matches(request: Request, user1: str, user2: str, status: str = "P errored_users = _handle_errors(errors, user1, user2) fmt = ", ".join(errored_users) - return Response(f"Sorry, it seems that user(s) {fmt} are not found.") + return Response(f"Sorry, it seems that user(s) {fmt} are not found.", status_code=404) try: matching_items = _get_common_planning(data) # type: ignore # the type is resolved above.