diff --git "a/include/class-mw\\API\\Exception.php" "b/include/class-mw\\API\\Exception.php" index 37f72c7..b7eced4 100644 --- "a/include/class-mw\\API\\Exception.php" +++ "b/include/class-mw\\API\\Exception.php" @@ -1,102 +1,108 @@ . # MediaWiki API namespace mw\API; /** * Generic API exception class */ class Exception extends \Exception { /** * API error object * * @var object */ private $apiError; /** * Constructor * * @param $api_error object The complete error * @param $code int * @param $previous object */ public function __construct( $api_error, $code = 0, Exception $previous = null ) { $this->apiError = $api_error; parent::__construct( sprintf( "API error code: '%s' info: '%s'", $this->getApiErrorCode(), $this->getApiErrorInfo() ), $code, $previous ); } /** * Create a specific exception from a generic API error * * @param $api_error object The complete error * @return self */ public static function createFromApiError( $api_error ) { $exception = new self( $api_error ); $code = $exception->getApiErrorCode(); switch( $code ) { case 'bad-token': $exception = new BadTokenException( $api_error ); break; case 'maxlag': $exception = new MaxLagException( $api_error ); break; case 'articleexists': $exception = new ArticleExistsException( $api_error ); break; + case 'missingtitle': + $exception = new MissingTitleException( $api_error ); + break; + case 'protectedpage': + $exception = new ProtectedPageException( $api_error ); + break; } return $exception; } /** * Get the complete error object * * @return object */ public function getApiError() { return $this->apiError; } /** * Get the API error code * * @return string */ public function getApiErrorCode() { return $this->getApiError()->code; } /** * Get the API error info * * @return string */ public function getApiErrorInfo() { return $this->getApiError()->info; } } diff --git "a/include/class-mw\\API\\MissingTitleException.php" "b/include/class-mw\\API\\MissingTitleException.php" new file mode 100644 index 0000000..6df5158 --- /dev/null +++ "b/include/class-mw\\API\\MissingTitleException.php" @@ -0,0 +1,24 @@ +. + +# MediaWiki API +namespace mw\API; + +/** + * Specific API exception class for the 'missingtitle' exception + */ +class MissingTitleException extends Exception {} diff --git "a/include/class-mw\\API\\ProtectedPageException.php" "b/include/class-mw\\API\\ProtectedPageException.php" new file mode 100644 index 0000000..cefe2fb --- /dev/null +++ "b/include/class-mw\\API\\ProtectedPageException.php" @@ -0,0 +1,24 @@ +. + +# MediaWiki API +namespace mw\API; + +/** + * Specific API exception class for the 'protectedpage' error code + */ +class ProtectedPageException extends Exception {}