Merge "Update searchdisabled message with docs and better link target"
[mediawiki.git] / includes / Rest / LocalizedHttpException.php
blob1980838c529b895d69cfc2e26c2bb2ee7ac3bba6
1 <?php
3 namespace MediaWiki\Rest;
5 use Wikimedia\Message\DataMessageValue;
6 use Wikimedia\Message\MessageValue;
8 /**
9 * @newable
11 class LocalizedHttpException extends HttpException {
12 private MessageValue $messageValue;
13 private string $errorKey;
15 /**
16 * @stable to call
18 * @param MessageValue $messageValue
19 * @param int $code
20 * @param array $errorData
22 public function __construct( MessageValue $messageValue, $code = 500, $errorData = [] ) {
23 if ( $messageValue instanceof DataMessageValue ) {
24 $errorKey = $messageValue->getCode();
25 $errorData += $messageValue->getData() ?? [];
26 } else {
27 $errorKey = $messageValue->getKey();
29 parent::__construct(
30 'Localized exception with key ' . $messageValue->getKey(), $code, $errorData
32 $this->messageValue = $messageValue;
33 $this->errorKey = $errorKey;
36 public function getMessageValue(): MessageValue {
37 return $this->messageValue;
40 public function getErrorKey(): string {
41 return $this->errorKey;