mediawiki-extensions-Discus.../includes/ContentThreadItemSetStatus.php
Bartosz Dziewoński 0b1919af0c Improve handling of Parsoid resource limit exceeded exceptions
Follow-up to 3d9585acbe.

* Avoid deprecated method StatusValue::getErrors()
* Don't use exceptions for control flow
* Don't re-use Parsoid's ResourceLimitExceededException,
  it seems unexpected to me and might limit future refactoring
* Use dieStatus() instead of dieWithException(), which will produce
  better localised error messages
* Add missing error handling in ApiDiscussionToolsThank

Change-Id: Ia032025f92f1c3cc0d62a0f45925dddba93fb42f
2024-11-28 04:09:44 +01:00

30 lines
693 B
PHP

<?php
namespace MediaWiki\Extension\DiscussionTools;
use MediaWiki\Status\Status;
use StatusValue;
use Wikimedia\NormalizedException\NormalizedException;
class ContentThreadItemSetStatus extends StatusValue {
/**
* Convenience method.
*/
public static function wrap( StatusValue $other ): self {
return ( new self )->merge( $other, true );
}
/**
* Like getValue(), but will throw if the value is null. Check isOK() first to avoid errors.
*/
public function getValueOrThrow(): ContentThreadItemSet {
$value = $this->getValue();
if ( $value === null ) {
throw new NormalizedException( ...Status::wrap( $this )->getPsr3MessageAndContext() );
}
return $value;
}
}