+ protected static function getErrorFormatter() {
+ if ( self::$errorFormatter === null ) {
+ self::$errorFormatter = new ApiErrorFormatter(
+ new ApiResult( false ),
+ Language::factory( 'en' ),
+ 'none'
+ );
+ }
+ return self::$errorFormatter;
+ }
+
+ public static function apiExceptionHasCode( ApiUsageException $ex, $code ) {
+ return (bool)array_filter(
+ self::getErrorFormatter()->arrayFromStatus( $ex->getStatusValue() ),
+ function ( $e ) use ( $code ) {
+ return is_array( $e ) && $e['code'] === $code;
+ }
+ );
+ }
+