diff options
author | jenkins-bot <jenkins-bot@gerrit.wikimedia.org> | 2019-11-13 06:15:51 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@wikimedia.org> | 2019-11-13 06:15:51 +0000 |
commit | 40b28c73a770df2c6ecbe538a23c737ef4c1fe4c (patch) | |
tree | 6dc607996f6148df7fb128bb9bbb9d23608f0f5d /includes/Rest | |
parent | 4b19ef70b49e46250c9ebc2701786f4b88986f56 (diff) | |
parent | aa0720d37ce2976aae6ee89337b9598cab59d3d0 (diff) | |
download | mediawikicore-40b28c73a770df2c6ecbe538a23c737ef4c1fe4c.tar.gz mediawikicore-40b28c73a770df2c6ecbe538a23c737ef4c1fe4c.zip |
Merge "ParamValidator: Use MessageValue!"
Diffstat (limited to 'includes/Rest')
-rw-r--r-- | includes/Rest/LocalizedHttpException.php | 6 | ||||
-rw-r--r-- | includes/Rest/Validator/ParamValidatorCallbacks.php | 6 | ||||
-rw-r--r-- | includes/Rest/Validator/Validator.php | 7 |
3 files changed, 12 insertions, 7 deletions
diff --git a/includes/Rest/LocalizedHttpException.php b/includes/Rest/LocalizedHttpException.php index 184fe164b77b..84067ac6605f 100644 --- a/includes/Rest/LocalizedHttpException.php +++ b/includes/Rest/LocalizedHttpException.php @@ -7,8 +7,10 @@ use Wikimedia\Message\MessageValue; class LocalizedHttpException extends HttpException { private $messageValue; - public function __construct( MessageValue $messageValue, $code = 500 ) { - parent::__construct( 'Localized exception with key ' . $messageValue->getKey(), $code ); + public function __construct( MessageValue $messageValue, $code = 500, $errorData = null ) { + parent::__construct( + 'Localized exception with key ' . $messageValue->getKey(), $code, $errorData + ); $this->messageValue = $messageValue; } diff --git a/includes/Rest/Validator/ParamValidatorCallbacks.php b/includes/Rest/Validator/ParamValidatorCallbacks.php index 93de9112c048..520eefdd2a30 100644 --- a/includes/Rest/Validator/ParamValidatorCallbacks.php +++ b/includes/Rest/Validator/ParamValidatorCallbacks.php @@ -7,8 +7,8 @@ use MediaWiki\Permissions\PermissionManager; use MediaWiki\Rest\RequestInterface; use MediaWiki\User\UserIdentity; use Psr\Http\Message\UploadedFileInterface; +use Wikimedia\Message\DataMessageValue; use Wikimedia\ParamValidator\Callbacks; -use Wikimedia\ParamValidator\ValidationException; class ParamValidatorCallbacks implements Callbacks { @@ -80,7 +80,9 @@ class ParamValidatorCallbacks implements Callbacks { return $upload instanceof UploadedFileInterface ? $upload : null; } - public function recordCondition( ValidationException $condition, array $options ) { + public function recordCondition( + DataMessageValue $message, $name, $value, array $settings, array $options + ) { // @todo Figure out how to handle warnings } diff --git a/includes/Rest/Validator/Validator.php b/includes/Rest/Validator/Validator.php index 0715b9fa1156..25f59b3636a0 100644 --- a/includes/Rest/Validator/Validator.php +++ b/includes/Rest/Validator/Validator.php @@ -5,6 +5,7 @@ namespace MediaWiki\Rest\Validator; use MediaWiki\Permissions\PermissionManager; use MediaWiki\Rest\Handler; use MediaWiki\Rest\HttpException; +use MediaWiki\Rest\LocalizedHttpException; use MediaWiki\Rest\RequestInterface; use MediaWiki\User\UserIdentity; use Wikimedia\ObjectFactory; @@ -98,12 +99,12 @@ class Validator { 'source' => $settings[Handler::PARAM_SOURCE] ?? 'unspecified', ] ); } catch ( ValidationException $e ) { - throw new HttpException( 'Parameter validation failed', 400, [ + throw new LocalizedHttpException( $e->getFailureMessage(), 400, [ 'error' => 'parameter-validation-failed', 'name' => $e->getParamName(), 'value' => $e->getParamValue(), - 'failureCode' => $e->getFailureCode(), - 'failureData' => $e->getFailureData(), + 'failureCode' => $e->getFailureMessage()->getCode(), + 'failureData' => $e->getFailureMessage()->getData(), ] ); } } |