[go: nahoru, domu]

Skip to content

Commit

Permalink
Throw exception for rejected page requests (#511)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
samwilson committed Apr 3, 2024
1 parent 0cf5727 commit d0b9509
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
3 changes: 3 additions & 0 deletions src/Util/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down
2 changes: 1 addition & 1 deletion tests/Http/BookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}

Expand Down

0 comments on commit d0b9509

Please sign in to comment.