Log errors in Http::request()
authorGergő Tisza <tgr.huwiki@gmail.com>
Wed, 8 Jul 2015 07:39:52 +0000 (07:39 +0000)
committerBryanDavis <bdavis@wikimedia.org>
Tue, 28 Jul 2015 22:24:00 +0000 (22:24 +0000)
Instead of silently discarding errors in server-side HTTP requests,
log them to a 'http' channel.

Make ForeignAPIFile::httpGet() (which sort of reimplements Http::get())
log to the same channel, for consistency.

Bug: T103043
Change-Id: Ibf552e22adc7fde4a751f92e92dad6ceba2f335c

includes/HttpFunctions.php
includes/filerepo/ForeignAPIRepo.php

index 7b43a2d..fec8adc 100644 (file)
@@ -25,6 +25,8 @@
  * @defgroup HTTP HTTP
  */
 
  * @defgroup HTTP HTTP
  */
 
+use MediaWiki\Logger\LoggerFactory;
+
 /**
  * Various HTTP related functions
  * @ingroup HTTP
 /**
  * Various HTTP related functions
  * @ingroup HTTP
@@ -73,11 +75,14 @@ class Http {
                $req = MWHttpRequest::factory( $url, $options, $caller );
                $status = $req->execute();
 
                $req = MWHttpRequest::factory( $url, $options, $caller );
                $status = $req->execute();
 
-               $content = false;
                if ( $status->isOK() ) {
                if ( $status->isOK() ) {
-                       $content = $req->getContent();
+                       return $req->getContent();
+               } else {
+                       $errors = $status->getErrorsByType( 'error' );
+                       $logger = LoggerFactory::getInstance( 'http' );
+                       $logger->warning( $status->getWikiText(), array( 'caller' => $caller ) );
+                       return false;
                }
                }
-               return $content;
        }
 
        /**
        }
 
        /**
index ec84762..4ffbf4a 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup FileRepo
  */
 
  * @ingroup FileRepo
  */
 
+use MediaWiki\Logger\LoggerFactory;
+
 /**
  * A foreign repository with a remote MediaWiki with an API thingy
  *
 /**
  * A foreign repository with a remote MediaWiki with an API thingy
  *
@@ -521,7 +523,8 @@ class ForeignAPIRepo extends FileRepo {
                if ( $status->isOK() ) {
                        return $req->getContent();
                } else {
                if ( $status->isOK() ) {
                        return $req->getContent();
                } else {
-                       wfDebug( "ForeignAPIRepo: ERROR on GET: " . $status->getWikiText() );
+                       $logger = LoggerFactory::getInstance( 'http' );
+                       $logger->warning( $status->getWikiText(), array( 'caller' => 'ForeignAPIRepo::httpGet' ) );
                        return false;
                }
        }
                        return false;
                }
        }