Merge pull request #451 from jjlawren/raise_notfound

Raise NotFound on 404 errors
This commit is contained in:
Steffen Fredriksen 2020-04-16 14:41:14 +02:00 committed by GitHub
commit 0da9e3994a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 1 deletions

View file

@ -5,7 +5,7 @@ import requests
from plexapi import BASE_HEADERS, CONFIG, TIMEOUT, log, logfilter, utils
from plexapi.base import PlexObject
from plexapi.compat import ElementTree
from plexapi.exceptions import BadRequest, Unauthorized, Unsupported
from plexapi.exceptions import BadRequest, NotFound, Unauthorized, Unsupported
from plexapi.playqueue import PlayQueue
from requests.status_codes import _codes as codes
@ -163,6 +163,8 @@ class PlexClient(PlexObject):
message = '(%s) %s; %s %s' % (response.status_code, codename, response.url, errtext)
if response.status_code == 401:
raise Unauthorized(message)
elif response.status_code == 404:
raise NotFound(message)
else:
raise BadRequest(message)
data = response.text.encode('utf8')

View file

@ -185,6 +185,8 @@ class MyPlexAccount(PlexObject):
message = '(%s) %s; %s %s' % (response.status_code, codename, response.url, errtext)
if response.status_code == 401:
raise Unauthorized(message)
elif response.status_code == 404:
raise NotFound(message)
else:
raise BadRequest(message)
data = response.text.encode('utf8')

View file

@ -427,6 +427,8 @@ class PlexServer(PlexObject):
message = '(%s) %s; %s %s' % (response.status_code, codename, response.url, errtext)
if response.status_code == 401:
raise Unauthorized(message)
elif response.status_code == 404:
raise NotFound(message)
else:
raise BadRequest(message)
data = response.text.encode('utf8')

View file

@ -90,6 +90,11 @@ def _detect_color_image(file, thumb_size=150, MSE_cutoff=22, adjust_color_bias=T
return 'blackandwhite'
def test_server_fetchitem_notfound(plex):
with pytest.raises(NotFound):
plex.fetchItem(123456789)
def test_server_search(plex, movie):
title = movie.title
# this search seem to fail on my computer but not at travis, wtf.