Tim Starling has submitted this change and it was merged.
Change subject: Propagate Http errors back up in the form of a Status
......................................................................
Propagate Http errors back up in the form of a Status
Change-Id: I6146781d5cf26029809699f576fde0c21dab0906
---
M MWSearch.i18n.php
M MWSearch_body.php
2 files changed, 25 insertions(+), 7 deletions(-)
Approvals:
Tim Starling: Verified; Looks good to me, approved
jenkins-bot: Checked
diff --git a/MWSearch.i18n.php b/MWSearch.i18n.php
index 851baeb..f344504 100644
--- a/MWSearch.i18n.php
+++ b/MWSearch.i18n.php
@@ -10,6 +10,7 @@
$messages['en'] = array(
'mwsearch-desc' => 'MWSearch plugin',
+ 'mwsearch-backend-error' => 'The search backend returned an error: $1'
);
/** Message documentation (Message documentation)
diff --git a/MWSearch_body.php b/MWSearch_body.php
index b4d57bb..dfdbf4e 100644
--- a/MWSearch_body.php
+++ b/MWSearch_body.php
@@ -475,24 +475,41 @@
wfDebugLog( 'mwsearch', "Fetching search data from
$searchUrl\n" );
$work = new PoolCounterWorkViaCallback( 'LuceneSearchRequest',
"_lucene:host:$host",
- array( 'doWork' => function() use ( $host, $searchUrl,
$httpOpts ) {
+ array( 'doWork' => function() use ( $host, $searchUrl )
{
global $wgLuceneSearchTimeout;
+ wfDebug( "Fetching search data from
$searchUrl\n" );
wfSuppressWarnings();
$httpProfile ="LuceneSearchSet::newFromQuery" .
'-contact-' . $host;
wfProfileIn( $httpProfile );
- $data = Http::get( $searchUrl,
$wgLuceneSearchTimeout, $httpOpts );
+
+ $req = MWHttpRequest::factory( $searchUrl,
+ array( 'proxy' => false, 'timeout' =>
$wgLuceneSearchTimeout ) );
+ $status = $req->execute();
+ $content = $req->getContent();
+ $m = array();
+ if ( $req->getStatus() == 500
+ && $req->getResponseHeader(
'Content-Type' ) == 'text/html'
+ && preg_match(
'/<div>([^>]*)<\/div>/i', $content, $m ) )
+ {
+ $status = Status::newFatal(
'mwsearch-backend-error', $m[1] );
+ wfDebugLog( 'mwsearch', 'Search backend
error: ' . $m[1] );
+ } else {
+ $status->value = $content;
+ }
+
wfProfileOut( $httpProfile );
wfRestoreWarnings();
- return $data;
+ return $status;
} ) );
- $data = $work->execute();
- if( $data === false ) {
+ $workStatus = $work->execute();
+
+ if( !$workStatus->isGood() ) {
// Network error or server error
wfProfileOut( __METHOD__ );
- return null;
+ return $workStatus;
} else {
- $inputLines = explode( "\n", trim( $data ) );
+ $inputLines = explode( "\n", trim( $workStatus->value )
);
$resultLines = array_map( 'trim', $inputLines );
}
--
To view, visit https://gerrit.wikimedia.org/r/57337
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6146781d5cf26029809699f576fde0c21dab0906
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/MWSearch
Gerrit-Branch: master
Gerrit-Owner: Demon <[email protected]>
Gerrit-Reviewer: Demon <[email protected]>
Gerrit-Reviewer: Ram <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits