| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Rest; |
| 4 |
|
| 5 |
use Wikimedia\Message\DataMessageValue; |
| 6 |
use Wikimedia\Message\MessageValue; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
class LocalizedHttpException extends HttpException { |
| 12 |
private MessageValue $messageValue; |
| 13 |
private string $errorKey; |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 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(); |
| 28 |
} |
| 29 |
parent::__construct( |
| 30 |
'Localized exception with key ' . $messageValue->getKey(), $code, $errorData |
| 31 |
); |
| 32 |
$this->messageValue = $messageValue; |
| 33 |
$this->errorKey = $errorKey; |
| 34 |
} |
| 35 |
|
| 36 |
public function getMessageValue(): MessageValue { |
| 37 |
return $this->messageValue; |
| 38 |
} |
| 39 |
|
| 40 |
public function getErrorKey(): string { |
| 41 |
return $this->errorKey; |
| 42 |
} |
| 43 |
} |