From 0bc9977541000b4ad4527b4342b5062578f264ce Mon Sep 17 00:00:00 2001 From: l3uddz Date: Fri, 9 Mar 2018 11:59:34 +0000 Subject: [PATCH] should catch error reasons more regardless of status_code --- media/radarr.py | 5 +++-- media/sonarr.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/media/radarr.py b/media/radarr.py index a2dad65..eade2a0 100644 --- a/media/radarr.py +++ b/media/radarr.py @@ -98,8 +98,9 @@ class Radarr: if req.status_code == 201 and req.json()['tmdbId'] == movie_tmdbid: log.debug("Successfully added %s (%d)", movie_title, movie_tmdbid) return True - elif req.status_code == 409 and 'message' in req.text: - log.error("Failed to add %s (%d), reason: %s", movie_title, movie_tmdbid, req.json()['message']) + elif 'json' in req.headers['Content-Type'].lower() and 'message' in req.text: + log.error("Failed to add %s (%d) - status_code: %d, reason: %s", movie_title, movie_tmdbid, + req.status_code, req.json()['message']) return False else: log.error("Failed to add %s (%d), unexpected response:\n%s", movie_title, movie_tmdbid, req.text) diff --git a/media/sonarr.py b/media/sonarr.py index 7030f2f..22452d9 100644 --- a/media/sonarr.py +++ b/media/sonarr.py @@ -144,8 +144,9 @@ class Sonarr: if req.status_code == 201 and req.json()['tvdbId'] == series_tvdbid: log.debug("Successfully added %s (%d)", series_title, series_tvdbid) return True - elif req.status_code == 401 and 'errorMessage' in req.text: - log.error("Failed to add %s (%d), reason: %s", series_title, series_tvdbid, req.json()['errorMessage']) + elif 'json' in req.headers['Content-Type'].lower() and 'errorMessage' in req.text: + log.error("Failed to add %s (%d) - status_code: %d, reason: %s", series_title, series_tvdbid, + req.status_code, req.json()['errorMessage']) return False else: log.error("Failed to add %s (%d), unexpected response:\n%s", series_title, series_tvdbid, req.text)