Check for response status 200 on jellyfin query

This commit is contained in:
Luigi311
2023-03-08 21:49:56 -07:00
parent 13b4ff3215
commit dc1fe11590
3 changed files with 44 additions and 21 deletions

View File

@@ -38,17 +38,24 @@ class Jellyfin:
async with session.get(
self.baseurl + query, headers=headers
) as response:
if response.status != 200:
raise Exception(
f"Query failed with status {response.status} {response.reason}"
)
results = await response.json()
elif query_type == "post":
async with session.post(
self.baseurl + query, headers=headers
) as response:
if response.status != 200:
raise Exception(
f"Query failed with status {response.status} {response.reason}"
)
results = await response.json()
if type(results) is str:
logger(f"Jellyfin: Query {query_type} {query} {results}", 2)
raise Exception(results)
if not isinstance(results, list) and not isinstance(results, dict):
raise Exception("Query result is not of type list or dict")
# append identifiers to results
if identifiers:
@@ -57,7 +64,7 @@ class Jellyfin:
return results
except Exception as e:
logger(f"Jellyfin: Query failed {e}", 2)
logger(f"Jellyfin: Query {query_type} {query}\nResults {results}\n{e}", 2)
raise Exception(e)
async def get_users(self):
@@ -393,12 +400,7 @@ class Jellyfin:
# If there are multiple types in library raise error
if types is None or len(types) < 1:
all_types = set(
[
x["Type"]
for x in watched["Items"]
]
)
all_types = set([x["Type"] for x in watched["Items"]])
logger(
f"Jellyfin: Skipping Library {library_title} found types: {types}, all types: {all_types}",
1,