Print errors to stderr

This commit is contained in:
Mike Schwörer 2021-12-15 15:15:16 +01:00
parent 1de70483fe
commit e20483084f
No known key found for this signature in database
GPG Key ID: D3C7172E0A70F8CF
3 changed files with 16 additions and 7 deletions

View File

@ -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

View File

@ -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:

View File

@ -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