2019-07-15 10:24:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MediaWiki\Rest;
|
|
|
|
|
|
2023-01-21 20:31:09 +00:00
|
|
|
use Wikimedia\Message\DataMessageValue;
|
2019-07-15 10:24:38 +00:00
|
|
|
use Wikimedia\Message\MessageValue;
|
|
|
|
|
|
2020-06-29 12:13:29 +00:00
|
|
|
/**
|
|
|
|
|
* @newable
|
|
|
|
|
*/
|
2019-07-15 10:24:38 +00:00
|
|
|
class LocalizedHttpException extends HttpException {
|
2023-01-21 20:31:09 +00:00
|
|
|
private MessageValue $messageValue;
|
|
|
|
|
private string $errorKey;
|
2019-07-16 22:43:43 +00:00
|
|
|
|
2020-06-29 12:13:29 +00:00
|
|
|
/**
|
2020-07-13 08:53:06 +00:00
|
|
|
* @stable to call
|
2020-06-29 12:13:29 +00:00
|
|
|
*
|
|
|
|
|
* @param MessageValue $messageValue
|
|
|
|
|
* @param int $code
|
2023-01-21 20:31:09 +00:00
|
|
|
* @param array $errorData
|
2020-06-29 12:13:29 +00:00
|
|
|
*/
|
2023-01-21 20:31:09 +00:00
|
|
|
public function __construct( MessageValue $messageValue, $code = 500, $errorData = [] ) {
|
|
|
|
|
if ( $messageValue instanceof DataMessageValue ) {
|
|
|
|
|
$errorKey = $messageValue->getCode();
|
|
|
|
|
$errorData += $messageValue->getData() ?? [];
|
|
|
|
|
} else {
|
|
|
|
|
$errorKey = $messageValue->getKey();
|
|
|
|
|
}
|
2019-09-12 17:44:11 +00:00
|
|
|
parent::__construct(
|
|
|
|
|
'Localized exception with key ' . $messageValue->getKey(), $code, $errorData
|
|
|
|
|
);
|
2019-07-16 22:43:43 +00:00
|
|
|
$this->messageValue = $messageValue;
|
2023-01-21 20:31:09 +00:00
|
|
|
$this->errorKey = $errorKey;
|
2019-07-16 22:43:43 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-21 20:31:09 +00:00
|
|
|
public function getMessageValue(): MessageValue {
|
2019-07-16 22:43:43 +00:00
|
|
|
return $this->messageValue;
|
2019-07-15 10:24:38 +00:00
|
|
|
}
|
2023-01-21 20:31:09 +00:00
|
|
|
|
|
|
|
|
public function getErrorKey(): string {
|
|
|
|
|
return $this->errorKey;
|
|
|
|
|
}
|
2019-07-15 10:24:38 +00:00
|
|
|
}
|