New error message when the page doesn't exist

The previous confusing error was coming from the getLatestRevision() call.

Bug: T273068
Change-Id: I5bb53c875bb08f6fb087875a6e55fb033d182056
This commit is contained in:
Bartosz Dziewoński 2021-01-27 16:40:57 +01:00
parent 20a9836c73
commit f21e6dfc7c

View file

@ -98,6 +98,17 @@ class ApiDiscussionToolsEdit extends ApiBase {
break;
case 'addcomment':
$commentId = $params['commentid'] ?? null;
if ( !$commentId ) {
$this->dieWithError( [ 'apierror-missingparam', 'commentid' ] );
}
if ( !$title->exists() ) {
// The page does not exist, so the comment we're trying to reply to can't exist either.
$this->dieWithError( [ 'apierror-discussiontools-commentid-notfound', $commentId ] );
}
// Fetch the latest revision
$requestedRevision = $this->getLatestRevision( $title );
$response = $this->requestRestbasePageHtml( $requestedRevision );
@ -133,12 +144,6 @@ class ApiDiscussionToolsEdit extends ApiBase {
$container = $doc->getElementsByTagName( 'body' )->item( 0 );
'@phan-var DOMElement $container';
$commentId = $params['commentid'] ?? null;
if ( !$commentId ) {
$this->dieWithError( [ 'apierror-missingparam', 'commentid' ] );
}
$parser = CommentParser::newFromGlobalState( $container );
$comment = $parser->findCommentById( $commentId );