adding json decode fail catch
This commit is contained in:
parent
24dfc77d63
commit
0561b0036e
@ -7,6 +7,8 @@ from time import sleep
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from datetime import datetime, date, time, timedelta
|
from datetime import datetime, date, time, timedelta
|
||||||
|
|
||||||
|
from requests import JSONDecodeError
|
||||||
|
|
||||||
from fmframework.model import Album, Artist, Image, Wiki, WeeklyChart, Scrobble, Track
|
from fmframework.model import Album, Artist, Image, Wiki, WeeklyChart, Scrobble, Track
|
||||||
|
|
||||||
|
|
||||||
@ -56,6 +58,8 @@ class Network:
|
|||||||
params=params,
|
params=params,
|
||||||
json=json,
|
json=json,
|
||||||
data=data)
|
data=data)
|
||||||
|
|
||||||
|
try:
|
||||||
resp = response.json()
|
resp = response.json()
|
||||||
|
|
||||||
if 200 <= response.status_code < 300:
|
if 200 <= response.status_code < 300:
|
||||||
@ -71,7 +75,7 @@ class Network:
|
|||||||
if self.retry_counter < 5:
|
if self.retry_counter < 5:
|
||||||
self.retry_counter += 1
|
self.retry_counter += 1
|
||||||
sleep(2)
|
sleep(2)
|
||||||
logger.warning(f'{method} {response.status_code} {code} {message} retyring')
|
logger.warning(f'{method} {response.status_code} {code} {message} retrying')
|
||||||
return self.net_call(http_method=http_method,
|
return self.net_call(http_method=http_method,
|
||||||
method=method,
|
method=method,
|
||||||
params=params,
|
params=params,
|
||||||
@ -84,6 +88,10 @@ class Network:
|
|||||||
logger.error(f'{method} {response.status_code} {code} {message} retry limit reached')
|
logger.error(f'{method} {response.status_code} {code} {message} retry limit reached')
|
||||||
raise LastFMNetworkException(http_code=response.status_code, error_code=code, message=message)
|
raise LastFMNetworkException(http_code=response.status_code, error_code=code, message=message)
|
||||||
|
|
||||||
|
except JSONDecodeError:
|
||||||
|
logger.warning(f"failed to decode json from resp, {method} {response} -> {response.content}")
|
||||||
|
return {}
|
||||||
|
|
||||||
def get_request(self,
|
def get_request(self,
|
||||||
method: str,
|
method: str,
|
||||||
params: dict = None,
|
params: dict = None,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "fmframework"
|
name = "fmframework"
|
||||||
version = "1.0.0"
|
version = "1.0.1"
|
||||||
description = "Last.fm HTTP wrapper library"
|
description = "Last.fm HTTP wrapper library"
|
||||||
authors = ["andy <andy@sarsoo.xyz>"]
|
authors = ["andy <andy@sarsoo.xyz>"]
|
||||||
repository = "https://github.com/Sarsoo/fmframework"
|
repository = "https://github.com/Sarsoo/fmframework"
|
||||||
|
Loading…
Reference in New Issue
Block a user