return GotifyErrorModel in upload_application_image

This commit is contained in:
dries.k
2022-07-21 10:50:10 +02:00
parent 1aa324eebf
commit a7b1f2064b

View File

@@ -113,13 +113,17 @@ class GotifyClient(GotifySession):
def upload_application_image( def upload_application_image(
self, application_id: int, img_path: str self, application_id: int, img_path: str
) -> Optional[GotifyApplicationModel]: ) -> Optional[Union[GotifyApplicationModel, GotifyErrorModel]]:
try: try:
with open(img_path, "rb") as f: with open(img_path, "rb") as f:
response = self._post( response = self._post(
f"/application/{application_id}/image", files={"file": f} f"/application/{application_id}/image", files={"file": f}
) )
return response.json() if response.ok else None return (
GotifyApplicationModel(response.json())
if response.ok
else GotifyErrorModel(response)
)
except FileNotFoundError: except FileNotFoundError:
logger.error( logger.error(
f"GotifyClient.upload_application_image: image '{img_path}' not found." f"GotifyClient.upload_application_image: image '{img_path}' not found."