r61409 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61408‎ | r61409 | r61410 >
Date:09:47, 23 January 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Add more error handling and logging to google tm suggestions
Modified paths:
  • /trunk/extensions/Translate/utils/TranslationHelpers.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/utils/TranslationHelpers.php
@@ -237,6 +237,14 @@
238238 $path .= wfArrayToCgi( $query );
239239 $google_json = Http::get( $path, 2 );
240240 $response = json_decode( $google_json );
 241+ if ( $google_json === false ) {
 242+ wfWarn( __METHOD__ . ': Http::get failed' );
 243+ return null;
 244+ } elseif( !is_object( $response ) ) {
 245+ wfWarn( __METHOD__ . ': Unable to parse reply: ' . strval( $google_json ) );
 246+ error_log( __METHOD__ . ': Unable to parse reply: ' . strval( $google_json ) );
 247+ return null;
 248+ }
241249 if ( $response->responseStatus === 200 ) {
242250 $text = $this->suggestionField( $response->responseData->translatedText );
243251 return Html::rawElement( 'div', null, self::legend('Google') . $text . self::clear() );
@@ -246,7 +254,7 @@
247255 } else {
248256 wfWarn( __METHOD__ . ': ' . $response->responseDetails );
249257 error_log( __METHOD__ . ': ' . $response->responseDetails );
250 - return false;
 258+ return null;
251259 }
252260 }
253261

Status & tagging log