From 7d4857fc5bcd08e4748944770e89ed6f724f7b48 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 18 Oct 2012 17:09:23 +0200 Subject: [PATCH] Catch all 4**/5** responses --- src/Composer/Util/RemoteFilesystem.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index f7f7f93f9..065ea3bee 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -107,6 +107,7 @@ class RemoteFilesystem } $errorMessage = ''; + $errorCode = 0; set_error_handler(function ($code, $msg) use (&$errorMessage) { if ($errorMessage) { $errorMessage .= "\n"; @@ -129,8 +130,9 @@ class RemoteFilesystem } // fix for 5.4.0 https://bugs.php.net/bug.php?id=61336 - if (!empty($http_response_header[0]) && preg_match('{^HTTP/\S+ 404}i', $http_response_header[0])) { + if (!empty($http_response_header[0]) && preg_match('{^HTTP/\S+ ([45]\d\d)}i', $http_response_header[0], $match)) { $result = false; + $errorCode = $match[1]; } // decode gzip @@ -181,7 +183,12 @@ class RemoteFilesystem } if (false === $this->result) { - throw new TransportException('The "'.$fileUrl.'" file could not be downloaded: '.$errorMessage); + $e = new TransportException('The "'.$fileUrl.'" file could not be downloaded: '.$errorMessage, $errorCode); + if (!empty($http_response_header[0])) { + $e->setHeaders($http_response_header); + } + + throw $e; } }