jenkins-bot has submitted this change and it was merged.

Change subject: Retry parse call if it fails to get section
......................................................................


Retry parse call if it fails to get section

Some pages don't support extracting sections.  If the parse FauxRequest
fails then try again without the request to get a section.

Bug T78721

Change-Id: I37320208af38ea39e80b292b009bbaa7ab6d1c96
---
M ApiQueryExtracts.php
1 file changed, 17 insertions(+), 2 deletions(-)

Approvals:
  Anomie: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/ApiQueryExtracts.php b/ApiQueryExtracts.php
index 2b76b79..add3993 100644
--- a/ApiQueryExtracts.php
+++ b/ApiQueryExtracts.php
@@ -211,8 +211,23 @@
                }
                // in case of cache miss, render just the needed section
                $api = new ApiMain( new FauxRequest( $request ) );
-               $api->execute();
-               $data = $api->getResultData();
+               try {
+                       $api->execute();
+                       $data = $api->getResultData();
+               } catch ( UsageException $e ) {
+                       if ( $e->getCodeString() === 'nosuchsection' ) {
+                               // Looks like we tried to get the intro to a 
page without
+                               // sections!  Lets just grab what we can get.
+                               unset( $request['section'] );
+                               $api = new ApiMain( new FauxRequest( $request ) 
);
+                               $api->execute();
+                               $data = $api->getResultData();
+                       } else {
+                               // Some other unexpected error - lets just 
report it to the user
+                               // on the off chance that is the right thing.
+                               throw $e;
+                       }
+               }
                wfProfileOut( __METHOD__ );
                return $data['parse']['text']['*'];
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/180485
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I37320208af38ea39e80b292b009bbaa7ab6d1c96
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TextExtracts
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: Waldir <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to