Skip to content

Commit

Permalink
Check the http status code before using Response
Browse files Browse the repository at this point in the history
This was causing a more difficult to understand failure in the JSON
parser so let's do it the more correct way. Check the response code
before trying to parse the response content.

Signed-off-by: Eric B Munson <eric@munsonfam.org>
  • Loading branch information
khers committed Jan 18, 2024
1 parent b0a73c9 commit 0789740
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
##4.0.6

Check the http status code before trying to use the Response object.

##4.0.5

Fiddly bits of packaging...
Expand Down
2 changes: 1 addition & 1 deletion src/libopensonic/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@


#Semantic versioning string for the library
__version__ = '4.0.5'
__version__ = '4.0.6'
6 changes: 4 additions & 2 deletions src/libopensonic/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2451,20 +2451,22 @@ def _doRequestWithLists(self, methodName, listMap, query=None):
url = f"{self._baseUrl}:{self._port}/{self._serverPath}/{methodName}"

if self._useGET:
res = requests.get(url, params=qdict)
res = requests.get(url, params=qdict, timeout=(60,300))
else:
res = requests.post(url, data=qdict)
res = requests.post(url, data=qdict, timeout=(60,300))

return res


def _handleInfoRes(self, res):
# Returns a parsed dictionary version of the result
res.raise_for_status()
dres = res.json()
return dres['subsonic-response']


def _handleBinRes(self, res):
res.raise_for_status()
contType = res.headers['Content-Type'] if 'Content-Type' in res.headers else None

if contType:
Expand Down

0 comments on commit 0789740

Please sign in to comment.