From 21546019c3ba3a308061c0ba701a2160d2d8a827 Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Sat, 16 Aug 2025 23:28:24 +0100 Subject: [PATCH] Replace echos with proper Exception and trigger_error() Signed-off-by: Markus Birth --- src/Mp3FileRemote.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Mp3FileRemote.php b/src/Mp3FileRemote.php index 9bfb5ac..58d0c55 100644 --- a/src/Mp3FileRemote.php +++ b/src/Mp3FileRemote.php @@ -72,9 +72,7 @@ class Mp3FileRemote do { // make sure we have this block - if (!$this->downloadBlock($blockId)) { - throw new Exception('Error downloading block ' . $blockId . ' (starting at pos. ' . ($blockId * $this->blockSize) . ')!'); - } + $this->downloadBlock($blockId); if ($blockPos + $numBytes >= $this->blockSize) { // length of request is more than this block has, truncate to block len $subLen = $this->blockSize - $blockPos; @@ -138,7 +136,7 @@ class Mp3FileRemote * * @param int $blockNo Block to download * - * @return bool TRUE if successful + * @return bool TRUE if successful, Exception on errors */ protected function downloadBlock(int $blockNo): bool { @@ -166,11 +164,9 @@ class Mp3FileRemote $httpStatus = explode(' ', $status['wrapper_data'][0])[1]; if ($httpStatus != '206') { if ($httpStatus != '200') { - echo 'Download error!' . PHP_EOL; - var_dump($status); - return false; + throw new Exception('Error downloading block ' . $blockNo . ' (starting at pos. ' . $bytesFrom . ')!\n' . print_r($status, true)); } - echo 'Server doesn\'t support partial content!' . PHP_EOL; + trigger_error('Server doesn\'t support partial content! Downloading whole file.', E_USER_NOTICE); // Content received is whole file from start if ($blockNo != 0) { // move block to start if needed