diff options
author | Stefan Giehl <stefan@matomo.org> | 2020-12-10 05:03:41 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-10 05:03:41 +0300 |
commit | 06918eea4d2ca01298200348b40f57817433b931 (patch) | |
tree | 6e1642d80ec8b657c42aff12d73b43a6557b2697 /core | |
parent | 4451622a6355af2f6af95fa6090c7100cdd307fc (diff) |
Fix error message when fopen fails in Http class (#16846)
Diffstat (limited to 'core')
-rw-r--r-- | core/ErrorHandler.php | 15 | ||||
-rw-r--r-- | core/Http.php | 8 |
2 files changed, 19 insertions, 4 deletions
diff --git a/core/ErrorHandler.php b/core/ErrorHandler.php index 2d6c018bba..0bc6141ded 100644 --- a/core/ErrorHandler.php +++ b/core/ErrorHandler.php @@ -19,6 +19,8 @@ class ErrorHandler { private static $fatalErrorStackTrace = []; + private static $lastError = ''; + /** * Fatal errors in PHP do not leave behind backtraces, which can make it impossible to determine * the exact cause of one. We can, however, save a partial stack trace by remembering certain execution @@ -132,6 +134,8 @@ class ErrorHandler public static function errorHandler($errno, $errstr, $errfile, $errline) { + self::$lastError = self::createLogMessage($errno, $errstr, $errfile, $errline); + // if the error has been suppressed by the @ we don't handle the error if (!(error_reporting() & $errno)) { return; @@ -174,6 +178,17 @@ class ErrorHandler } } + public static function getLastError() + { + $lastError = error_get_last(); + + if (!empty($lastError['message'])) { + return $lastError['message']; + } + + return self::$lastError; + } + private static function createLogMessage($errno, $errstr, $errfile, $errline) { return sprintf( diff --git a/core/Http.php b/core/Http.php index e0a99f544b..0347163ffe 100644 --- a/core/Http.php +++ b/core/Http.php @@ -246,7 +246,7 @@ class Http * @ignore */ Piwik::postEvent('Http.sendHttpRequest.end', array($aUrl, $httpEventParams, &$response, &$status, &$headers)); - + if ($destinationPath && file_exists($destinationPath)) { return true; } @@ -533,10 +533,10 @@ class Http if (isset($http_response_header) && preg_match('~^HTTP/(\d\.\d)\s+(\d+)(\s*.*)?~', implode("\n", $http_response_header), $m)) { $status = (int)$m[2]; } - + if (!$status && $response === false) { - $error = error_get_last(); - throw new \Exception($error['message']); + $error = ErrorHandler::getLastError(); + throw new \Exception($error); } $fileLength = strlen($response); } |