diff --git "a/include/class-mw\\API\\Exception.php" "b/include/class-mw\\API\\Exception.php" index 66780e5..0ad1f36 100644 --- "a/include/class-mw\\API\\Exception.php" +++ "b/include/class-mw\\API\\Exception.php" @@ -1,113 +1,114 @@ . # 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 ) { $known_exceptions = [ BadTokenException ::class, MaxLagException ::class, EditConflictException ::class, ArticleExistsException ::class, MissingTitleException ::class, ProtectedPageException ::class, PermissionDeniedException::class, ReadOnlyException ::class, ReadApiDeniedException ::class, PageCannotExistException ::class, + FailedSaveException ::class, // Wikibase related NoSuchEntityException ::class, ModificationFailedException::class, ]; $exception = new self( $api_error ); $code = $exception->getApiErrorCode(); foreach( $known_exceptions as $known_exception_name ) { if( $known_exception_name::API_ERROR_CODE === $code ) { $exception = new $known_exception_name( $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\\FailedSave.php" "b/include/class-mw\\API\\FailedSave.php" new file mode 100644 index 0000000..bc0365e --- /dev/null +++ "b/include/class-mw\\API\\FailedSave.php" @@ -0,0 +1,31 @@ +. + +# MediaWiki API +namespace mw\API; + +/** + * Specific API exception class for the 'failed-save' error code + * + * This error is throw when the wiki is unable to save, + * maybe because the database is under a weird condition. + */ +class FailedSaveException extends Exception { + + const API_ERROR_CODE = 'failed-save'; + +}