summaryrefslogtreecommitdiff
path: root/includes/exception/HttpError.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/exception/HttpError.php')
-rw-r--r--includes/exception/HttpError.php42
1 files changed, 41 insertions, 1 deletions
diff --git a/includes/exception/HttpError.php b/includes/exception/HttpError.php
index 6ab6e039..b81c5731 100644
--- a/includes/exception/HttpError.php
+++ b/includes/exception/HttpError.php
@@ -18,6 +18,8 @@
* @file
*/
+use MediaWiki\Logger\LoggerFactory;
+
/**
* Show an error that looks like an HTTP server error.
* Replacement for wfHttpError().
@@ -43,6 +45,19 @@ class HttpError extends MWException {
}
/**
+ * We don't want the default exception logging as we got our own logging set
+ * up in self::report.
+ *
+ * @see MWException::isLoggable
+ *
+ * @since 1.24
+ * @return bool
+ */
+ public function isLoggable() {
+ return false;
+ }
+
+ /**
* Returns the HTTP status code supplied to the constructor.
*
* @return int
@@ -52,11 +67,13 @@ class HttpError extends MWException {
}
/**
- * Report the HTTP error.
+ * Report and log the HTTP error.
* Sends the appropriate HTTP status code and outputs an
* HTML page with an error message.
*/
public function report() {
+ $this->doLog();
+
$httpMessage = HttpStatus::getMessage( $this->httpCode );
header( "Status: {$this->httpCode} {$httpMessage}", true, $this->httpCode );
@@ -65,6 +82,29 @@ class HttpError extends MWException {
print $this->getHTML();
}
+ private function doLog() {
+ $logger = LoggerFactory::getInstance( 'HttpError' );
+ $content = $this->content;
+
+ if ( $content instanceof Message ) {
+ $content = $content->text();
+ }
+
+ $context = array(
+ 'file' => $this->getFile(),
+ 'line' => $this->getLine(),
+ 'http_code' => $this->httpCode,
+ );
+
+ $logMsg = "$content ({http_code}) from {file}:{line}";
+
+ if ( $this->getStatusCode() < 500 ) {
+ $logger->info( $logMsg, $context );
+ } else {
+ $logger->error( $logMsg, $context );
+ }
+ }
+
/**
* Returns HTML for reporting the HTTP error.
* This will be a minimal but complete HTML document.