From a7b1f2064b453e5554677f5ca13f7724402543f8 Mon Sep 17 00:00:00 2001 From: "dries.k" Date: Thu, 21 Jul 2022 10:50:10 +0200 Subject: [PATCH] return GotifyErrorModel in upload_application_image --- gotify_tray/gotify/api.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gotify_tray/gotify/api.py b/gotify_tray/gotify/api.py index 432ca19..c7b53f2 100644 --- a/gotify_tray/gotify/api.py +++ b/gotify_tray/gotify/api.py @@ -113,13 +113,17 @@ class GotifyClient(GotifySession): def upload_application_image( self, application_id: int, img_path: str - ) -> Optional[GotifyApplicationModel]: + ) -> Optional[Union[GotifyApplicationModel, GotifyErrorModel]]: try: with open(img_path, "rb") as f: response = self._post( 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: logger.error( f"GotifyClient.upload_application_image: image '{img_path}' not found."