From d0b9509ed41acf4a8f9a5c09579f70e98b520bf5 Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Wed, 3 Apr 2024 18:52:47 +0800 Subject: [PATCH] Throw exception for rejected page requests (#511) This returns to the previous behaviour of throwing a WsExportException when a wiki page is not found. Also changes the error message to call it a 'page' rather than a 'book', becuase it could apply to a subpage or the root-level page, and it isn't referring to the whole book. Bug: T280329 --- i18n/en.json | 2 +- src/Util/Api.php | 3 +++ tests/Http/BookTest.php | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/i18n/en.json b/i18n/en.json index f1b65b29..b6feb36a 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -52,7 +52,7 @@ "alert-close": "Close", "export-failed": "Download failed.", "exception-url-fetch-error": "Unable to retrieve URL: $1", - "exception-rest-page-not-found": "The book '$1' could not be found.", + "exception-rest-page-not-found": "The page '$1' could not be found.", "learn-more": "Learn more.", "error-blocked-1": "Your IP address is currently blocked.", "error-blocked-2": "To prevent abuse from disruptive automation, WS Export denies access from logged out users that are globally blocked on Wikimedia wikis.", diff --git a/src/Util/Api.php b/src/Util/Api.php index 525c4107..1e91f871 100644 --- a/src/Util/Api.php +++ b/src/Util/Api.php @@ -292,6 +292,9 @@ public function getPageBatch( $titles ) { self::MAX_CONNECTIONS, function ( $text, $id ) use ( &$texts ) { $texts[$id] = $text; + }, + function ( $exception, $id ): never { + throw $exception; } )->wait(); $this->logger->debug( "Got responses for " . count( $texts ) . " pages" ); diff --git a/tests/Http/BookTest.php b/tests/Http/BookTest.php index 7e80911f..fc66861a 100644 --- a/tests/Http/BookTest.php +++ b/tests/Http/BookTest.php @@ -57,7 +57,7 @@ public function testGetPage( $title, $language ) { public function testGetNonExistingTitleDisplaysError() { $client = static::createClient(); $client->request( 'GET', '/book.php', [ 'page' => 'xxx' ] ); - $this->assertStringContainsString( "The book 'xxx' could not be found.", $client->getResponse()->getContent() ); + $this->assertStringContainsString( "The page 'xxx' could not be found.", $client->getResponse()->getContent() ); $this->assertSame( 404, $client->getResponse()->getStatusCode() ); }