From d0901c7267c06100bb7f2ec71d883f3ed6b351d1 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Tue, 9 Apr 2024 23:37:23 +0200 Subject: [PATCH] Fix issues creation --- scanner/providers/kyoo_client.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/scanner/providers/kyoo_client.py b/scanner/providers/kyoo_client.py index 7f95a3a9..5dfbdc7b 100644 --- a/scanner/providers/kyoo_client.py +++ b/scanner/providers/kyoo_client.py @@ -57,17 +57,28 @@ class KyooClient: return paths async def create_issue(self, path: str, issue: str, extra: dict | None = None): - await self.client.post( + async with self.client.post( f"{self._url}/issues", - json={"domain": "scanner", "cause": path, "reason": issue, "extra": extra}, + json={ + "domain": "scanner", + "cause": path, + "reason": issue, + "extra": extra if extra is not None else {}, + }, headers={"X-API-Key": self._api_key}, - ) + ) as r: + if not r.ok: + logger.error(f"Request error: {await r.text()}") + r.raise_for_status() async def delete_issue(self, path: str): - await self.client.delete( + async with self.client.delete( f'{self._url}/issues?filter=domain eq scanner and cause eq "{path}"', headers={"X-API-Key": self._api_key}, - ) + ) as r: + if not r.ok: + logger.error(f"Request error: {await r.text()}") + r.raise_for_status() async def link_collection( self, collection: str, type: Literal["movie"] | Literal["show"], id: str