mirror of
https://github.com/THIS-IS-NOT-A-BACKUP/zspotify.git
synced 2024-11-29 19:24:34 +01:00
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)
|
||||
|
||||
@classmethod
|
||||
def get_chunk_size(cls) -> int():
|
||||
def get_chunk_size(cls) -> int:
|
||||
return cls.get(CHUNK_SIZE)
|
||||
|
||||
@classmethod
|
||||
|
@ -1,3 +1,4 @@
|
||||
import sys
|
||||
from enum import Enum
|
||||
from tqdm import tqdm
|
||||
|
||||
@ -16,11 +17,17 @@ class PrintChannel(Enum):
|
||||
PROGRESS_INFO = PRINT_PROGRESS_INFO
|
||||
|
||||
|
||||
ERROR_CHANNEL = [PrintChannel.ERRORS, PrintChannel.API_ERRORS]
|
||||
|
||||
|
||||
class Printer:
|
||||
@staticmethod
|
||||
def print(channel: PrintChannel, msg: str) -> None:
|
||||
if ZSpotify.CONFIG.get(channel.value):
|
||||
print(msg)
|
||||
if channel in ERROR_CHANNEL:
|
||||
print(msg, file=sys.stderr)
|
||||
else:
|
||||
print(msg)
|
||||
|
||||
@staticmethod
|
||||
def print_loader(channel: PrintChannel, msg: str) -> None:
|
||||
|
@ -89,12 +89,14 @@ class ZSpotify:
|
||||
responsetext = response.text
|
||||
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']}")
|
||||
time.sleep(5)
|
||||
return cls.invoke_url(url, tryCount + 1)
|
||||
|
||||
|
||||
return responsetext, responsejson
|
||||
|
||||
@classmethod
|
||||
|
Loading…
Reference in New Issue
Block a user