ajax 失败返回
@param string|array $message
@param int $code
@param int $statusCode
@param array $errors
@param string $description
@return RestResponse
@throws \Exception
766148
public function renderFailure($message = '', $code = 10000, $statusCode = 400, $errors = [], $description = '') {
        $data = is_array($message) ? $message : [
            'code' => $code,
            'message' => $message
        ];
        if (!isset($data['code'])) {
            $data['code'] = $code;
        }
        if (!isset($data['message']) && !is_array($message)) {
            $data['message'] = $message;
        }
        if (!empty($errors)) {
            $data['errors'] = $errors;
        }
        if (!empty($description)) {
            $data['description'] = $description;
        }
        return $this->render($data, $statusCode);
    }
4308
public function throwException(
        $message,
        $code,
        $connectionErrorNumber = null,
        $httpStatusCode = null,
        $previousException = null
    ) {
        throw new PhpCapException(
            $message,
            $code,
            $connectionErrorNumber,
            $httpStatusCode,
            $previousException
        );
    }
120524
public function setStatusCode($statusCode, $message = null)
    {
        $this->statusCode = (int) $statusCode;

        // Add status message to meta array
        $this->addMeta(['status' => ['code' => (int) $statusCode]]);

        // Set optional status message if present
        if (!empty($message)) {
            $this->setStatusMessage($message);
        }

        return $this;
    }
1355105
public function sendError($code, $message = null)
    {
        if ($this->ajaxOnly === false) {
            output()->setContentType('application/json');
        }

        if (is_array($code)) {
            if (is_numeric(key($code))) {
                $message = reset($code);
                $code = key($code);
            } elseif (isset($code[ 'code' ])) {
                $code = $code[ 'code' ];
                $message = $code[ 'message' ];
            }
        }

        output()->sendError($code, $message);
    }
1232550
protected function message($message, $statusCode) {
		$response =  $this->getAPIResponse(array(
			'message' => $message,
			'statusCode' => $statusCode
		));
		$response->setStatusCode($statusCode);
		return $response;
	}
151730
public static function withErrorCode($errorCode, $message, $innerException= null)
	{
		$ex = new XPath2Exception( $message, $innerException );
		$ex->ErrorCode = $errorCode;
		return $ex;
	}
769713
public function onBeforeHTTPError($statusCode, $request)
    {
        if (Director::is_ajax()) {
            return;
        }
        $response = ErrorPage::response_for($statusCode);
        if ($response) {
            throw new HTTPResponse_Exception($response, $statusCode);
        }
    }
851337
public function setHeaderResponse($statusCode, $message = '')
    {
        $this->statusCode = $statusCode;
        $this->message = $message;
        if ($message == '') {
            $this->message = self::$defaultMessages[$statusCode];
        }

        if (empty($this->message)) {
            throw new RestException('Invalid http response status code: ' . $statusCode);
        }

        return $this;
    }
1044902
protected function returnError($description, $returnLink = true, $httpStatus = null)
    {
        if ($this->isXmlHttpRequest()) {
            $this->logWarning('Called '.__FUNCTION__.' in an unsupported AJAX context');
            throw new common_Exception($description);
        }

        $this->setData('message', $description);
        $this->setData('returnLink', $returnLink);

        if($httpStatus !== null && file_exists(Template::getTemplate("error/error${httpStatus}.tpl"))){
            $this->setView("error/error${httpStatus}.tpl", 'tao');
        } else {
            $this->setView('error/user_error.tpl', 'tao');
        }
    }
308366
public function errorResponse(string $errorCode = null, int $statusCode = null, $message = null):JsonResponse
    {
        return app(Responder::class)->error($errorCode, $statusCode, $message);
    }
627248
public static function response(string $message = null, int $code = null, array $headers = [])
  {
    $rest = new Rest;
    $rest->message = $message;

    if ($headers != []) {
      foreach($headers as $field => $i) {
        array_push($rest->headers, $field .': '. $i);
      }
    }

    if ($code != null) {
      $rest->code = $code;
      header('HTTP/1.1 '.$rest->code);
      return $rest->send();
    }

    return $rest;
  }
291784
protected static function loadResult($status, $code, $message, $errors, $extras)
    {
        $Result = new static($status);

        if (! empty($code)) {
            $Result->setCode($code);
        }

        if (! empty($message)) {
            $Result->setMessage($message);
        }

        if (! empty($errors)) {
            $Result->setErrors($errors);
        }

        if (! empty($extras)) {
            $Result->setExtras($extras);
        }

        return $Result;
    }
6183
public static function fromErrorCode($xsollaErrorCode, $message = '', $httpStatus = 500)
    {
        $body = [
            'error' => [
                'code' => $xsollaErrorCode,
                'message' => $message,
            ],
        ];
        $encodedBody = XsollaClient::jsonEncode($body);

        return new static($httpStatus, $encodedBody);
    }
857234
protected function response($message, $code)
  {
    Rest::response()->json([
      'status' => $message,
      'code' => $code
    ], $code);

    cancel();
  }
684602
public static function respond($status = 404, $message = '') {
        http_response_code($status);
        if (Request::isAjaxRequest()) {
            @header('ajax: 1');
            Response::getInstance()->output(['message' => $message ? $message : __('error occurred')]);
            Response::getInstance()->close();
        } else {
            if ($status == 404) {
                $data ['message'] = $message;
                $view             = template('404.tpl', $data);
            } else if ($status == 403) {
                $data ['message'] = $message;
                $view             = template('403.tpl', $data);
            } else if ($status == 500) {
                $data ['message'] = $message;
                $view             = template('500.tpl', $data);
            } else if ($status == 503) {
                $data ['message'] = $message;
                $view             = template('503.tpl', $data);
            } else if ($message) {
                if (is_array($message)) {
                    $view = new JsonView($message);
                } else {
                    $view = new SimpleView($message);
                }
            } else {
                $view = null;
            }
            if ($view) {
                Response::getInstance()->output($view);
                Response::getInstance()->close();
            }
        }
        exit (1);
    }
329629
public function setStatusCode(int $code, string $message = null)
    {
        $this->code = $code;
        $this->message = $message;

        return $this;
    }
286453
public function putStatus(string $code, Status $status = null, string $explanation = null): Assert
    {
        return $this->put($code, null, $status, $explanation);
    }