mirror of https://github.com/afkcodes/zspotify.git
Print errors to stderr
This commit is contained in:
parent
1de70483fe
commit
e20483084f
|
@ -158,7 +158,7 @@ class Config:
|
||||||
return cls.get(SPLIT_ALBUM_DISCS)
|
return cls.get(SPLIT_ALBUM_DISCS)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_chunk_size(cls) -> int():
|
def get_chunk_size(cls) -> int:
|
||||||
return cls.get(CHUNK_SIZE)
|
return cls.get(CHUNK_SIZE)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import sys
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
|
@ -16,11 +17,17 @@ class PrintChannel(Enum):
|
||||||
PROGRESS_INFO = PRINT_PROGRESS_INFO
|
PROGRESS_INFO = PRINT_PROGRESS_INFO
|
||||||
|
|
||||||
|
|
||||||
|
ERROR_CHANNEL = [PrintChannel.ERRORS, PrintChannel.API_ERRORS]
|
||||||
|
|
||||||
|
|
||||||
class Printer:
|
class Printer:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def print(channel: PrintChannel, msg: str) -> None:
|
def print(channel: PrintChannel, msg: str) -> None:
|
||||||
if ZSpotify.CONFIG.get(channel.value):
|
if ZSpotify.CONFIG.get(channel.value):
|
||||||
print(msg)
|
if channel in ERROR_CHANNEL:
|
||||||
|
print(msg, file=sys.stderr)
|
||||||
|
else:
|
||||||
|
print(msg)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def print_loader(channel: PrintChannel, msg: str) -> None:
|
def print_loader(channel: PrintChannel, msg: str) -> None:
|
||||||
|
|
|
@ -89,12 +89,14 @@ class ZSpotify:
|
||||||
responsetext = response.text
|
responsetext = response.text
|
||||||
responsejson = response.json()
|
responsejson = response.json()
|
||||||
|
|
||||||
if 'error' in responsejson and tryCount < 5:
|
if 'error' in responsejson:
|
||||||
|
if tryCount < 5:
|
||||||
|
Printer.print(PrintChannel.WARNINGS, f"Spotify API Error (try {tryCount}) ({responsejson['error']['status']}): {responsejson['error']['message']}")
|
||||||
|
time.sleep(5)
|
||||||
|
return cls.invoke_url(url, tryCount + 1)
|
||||||
|
|
||||||
Printer.print(PrintChannel.API_ERRORS, f"Spotify API Error ({responsejson['error']['status']}): {responsejson['error']['message']}")
|
Printer.print(PrintChannel.API_ERRORS, f"Spotify API Error ({responsejson['error']['status']}): {responsejson['error']['message']}")
|
||||||
time.sleep(5)
|
|
||||||
return cls.invoke_url(url, tryCount + 1)
|
|
||||||
|
|
||||||
return responsetext, responsejson
|
return responsetext, responsejson
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Reference in New Issue