Overview

Namespaces

  • LeanCloud
    • Engine
    • Operation
    • Storage
    • Uploader

Classes

  • LeanCloud\ACL
  • LeanCloud\AppRouter
  • LeanCloud\Bytes
  • LeanCloud\Client
  • LeanCloud\Engine\Cloud
  • LeanCloud\Engine\LaravelEngine
  • LeanCloud\Engine\LeanEngine
  • LeanCloud\Engine\SlimEngine
  • LeanCloud\File
  • LeanCloud\GeoPoint
  • LeanCloud\LeanObject
  • LeanCloud\MIMEType
  • LeanCloud\Operation\ArrayOperation
  • LeanCloud\Operation\DeleteOperation
  • LeanCloud\Operation\IncrementOperation
  • LeanCloud\Operation\RelationOperation
  • LeanCloud\Operation\SetOperation
  • LeanCloud\Push
  • LeanCloud\Query
  • LeanCloud\Region
  • LeanCloud\Relation
  • LeanCloud\Role
  • LeanCloud\RouteCache
  • LeanCloud\SaveOption
  • LeanCloud\SMS
  • LeanCloud\Storage\CookieStorage
  • LeanCloud\Storage\SessionStorage
  • LeanCloud\Uploader\QCloudUploader
  • LeanCloud\Uploader\QiniuUploader
  • LeanCloud\Uploader\S3Uploader
  • LeanCloud\Uploader\SimpleUploader
  • LeanCloud\User

Interfaces

  • LeanCloud\Operation\IOperation
  • LeanCloud\Storage\IStorage

Exceptions

  • LeanCloud\BatchRequestError
  • LeanCloud\CloudException
  • LeanCloud\Engine\FunctionError
  • Overview
  • Namespace
  • Class
 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 
<?php
namespace LeanCloud;

/**
 * BatchRequestError
 *
 * A BatchRequestError object consists of zero or more request and
 * response errors.
 *
 */
class BatchRequestError extends CloudException {

    /**
     * Array of error response
     *
     * @var array
     */
    private $errors = [];

    public function __construct($message="", $code = 1) {
        $message = empty($message) ? "Batch request error." : $message;
        parent::__construct($message, $code);
    }

    /**
     * Add failed request and its error response
     *
     * Both request and response are expected to be array. The response
     * array must contain an `error` message, while the request should
     * contain `method` and `path`.
     *
     * @return BatchRequestError
     */
    public function add($request, $response) {
        $error["code"] = isset($response["code"]) ? $response["code"] : 1;
        $error["error"] = "{$error['code']} {$response['error']}:"
                        . json_encode($request);
        $this->errors[] = $error;
        return $this;
    }

    /**
     * Get all error response
     *
     * @return array
     */
    public function getAll() {
        return $this->errors;
    }

    /**
     * Get first error response as map
     *
     * Returns associative array of following format:
     *
     * `{"code": 101, "error": "error message", "request": {...}}`
     *
     * @return array|null
     */
    public function getFirst() {
        return isset($this->errors[0]) ? $this->errors[0] : null;
    }

    /**
     * Contains error response or not
     *
     * @return bool
     */
    public function isEmpty() {
        return count($this->errors) == 0;
    }

    public function __toString() {
        $message = $this->message;
        if (!$this->isEmpty()) {
            $message .= json_encode($this->errors);
        }
        return __CLASS__ . ": [{$this->code}]: {$message}\n";
    }
}

API documentation generated by ApiGen