Factory method which returns a different exception based on the error
code
@param \SimpleJsonRpcClient\Response\Error $error
@return \SimpleJsonRpcClient\Exception\ResponseErrorException the exception
558923
public static function create(Error $error)
	{
		// Handle pre-defined single codes
		switch ($error->code)
		{
			case Error::CODE_PARSE_ERROR:
				return new ParseErrorException($error);
			case Error::CODE_INVALID_REQUEST:
				return new InvalidRequestException($error);
			case Error::CODE_METHOD_NOT_FOUND:
				return new MethodNotFoundException($error);
			case Error::CODE_INVALID_PARAMS:
				return new InvalidParamsException($error);
			case Error::CODE_INTERNAL_ERROR:
				return new InternalErrorException($error);
		}

		// Check for server error exceptions
		if ($error->code >= -32099 && $error->code <= -32000)
			return new ServerErrorException($error);

		// Implementation-specific
		return new ResponseErrorException($error);
	}
62526
public static function errToException($turnOn = true)
    {
        if (!$turnOn) {
            return set_error_handler(null);
        }

        /*
         * Error handler
         *
         * @param int $errno
         * @param string $errStr
         * @param string $errFile
         * @param int $errLine
         *
         * @throws ErrorException
         */
        $handler = function ($errno, $errStr, $errFile, $errLine) {
            // This error code is not included in error_reporting
            if (!(error_reporting() & $errno)) {
                return;
            }
            throw new ErrorException($errStr, 0, $errno, $errFile, $errLine);
        };

        return set_error_handler($handler);
    }
634672
protected function setError($key, $error)
    {
        gplcart_array_set($this->errors, $this->getKeyPath($key), $error);
        return $this->errors;
    }
66367
public function transform(Exception $exception)
    {
        if ($exception instanceof ExceptionInterface) {
            $exception = new BadRequestHttpException($exception->getMessage());
        }

        return $exception;
    }
557923
public static function failedToDecodeResponse(ResponseInterface $response, $error)
    {
        $response->getBody()->rewind();
        return new static(sprintf(
            "Failed to decode response '%s' with error '%s'",
            $response->getBody()->getContents(),
            $error
        ));
    }
1178952
private function pluckError(array $error) {
        $row = array_intersect_key(
            $error,
            ['field' => 1, 'error' => 1, 'code' => 1]
        );

        $row['message'] = $this->formatErrorMessage($error);
        return $row;
    }
711596
protected function exceptionHandler($exception)
    {
        switch (true) {
            case $exception instanceof RestException:
                $this->logger->notice($exception->getMessage(), $exception->getTrace());
                return $this->json($exception->getData(), $exception->getStatus());
            default:
                // TODO: Throw exception only in dev mode.
                throw $exception;
                $this->logger->error($exception->getMessage(), $exception->getTrace());
                return $this->json($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
        }
    }
641545
private static function imagesApplicationErrorToException($error) {
    switch($error->getApplicationError()) {
      case ImagesServiceError\ErrorCode::UNSPECIFIED_ERROR:
        $result = new CloudStorageException('Unspecified error with image.');
        break;
      case ImagesServiceError\ErrorCode::BAD_TRANSFORM_DATA:
        $result = new CloudStorageException('Bad image transform data.');
        break;
      case ImagesServiceError\ErrorCode::NOT_IMAGE:
        $result = new CloudStorageException('Not an image.');
        break;
      case ImagesServiceError\ErrorCode::BAD_IMAGE_DATA:
        $result = new CloudStorageException('Bad image data.');
        break;
      case ImagesServiceError\ErrorCode::IMAGE_TOO_LARGE:
        $result = new CloudStorageException('Image too large.');
        break;
      case ImagesServiceError\ErrorCode::INVALID_BLOB_KEY:
        $result = new CloudStorageException('Invalid blob key for image.');
        break;
      case ImagesServiceError\ErrorCode::ACCESS_DENIED:
        $result = new CloudStorageException('Access denied to image.');
        break;
      case ImagesServiceError\ErrorCode::OBJECT_NOT_FOUND:
        $result = new CloudStorageException('Image object not found.');
        break;
      default:
        $result = new CloudStorageException(
            'Images Error Code: ' . $error->getApplicationError());
    }
    return $result;
  }
223788
private function getExceptionClass($error)
    {
        $errors = [
            'PAUSED' => QueuePausedResponseException::class
        ];
        $exceptionClass = ResponseException::class;
        list($errorCode) = explode(" ", $error);
        if (!empty($errorCode) && isset($errors[$errorCode])) {
            $exceptionClass = $errors[$errorCode];
        }
        return $exceptionClass;
    }
1361718
public function getError($error, $opts=array()) {
		if (is_array($error) && isset($error['filter'])) {
			return $this->getErrorMessage($error['filter'], $error+$opts);
		} elseif (is_int($error)) {
			return $this->getErrorMessage($error, $opts);
		} else {
			return $this->getErrorMessage(0, $opts);
		}
	}
989263
private function translateError(FormError $error)
    {
        if ($this->translator === null) {
            return $error->getMessage();
        }

        if ($error->getMessagePluralization() !== null) {
            return $this->translator->transChoice(
                $error->getMessageTemplate(),
                $error->getMessagePluralization(),
                $error->getMessageParameters(),
                'validators'
            );
        }

        return $this->translator->trans(
            $error->getMessageTemplate(),
            $error->getMessageParameters(),
            'validators'
        );
    }
304410
public function addError($error)
    {
        if ($error instanceof self) {
            $this->errors = array_merge($this->errors, $error->errors);
        } else {
            $this->errors[] = $error;
        }

        return $this;
    }
1198996
public function setError($error, $code = \wf\model\Error::DEFAULT_MODEL_ERROR_CODE)
    {
        if ($error instanceof \wf\model\Error) {
            $this->error = $error;
        } elseif (is_scalar($error)) {
            $this->error = new \wf\model\Error($error, $code);
        } else {
            throw new \InvalidArgumentException('错误的消息类型');
        }

        return $this;
    }
536585
public function error(RESTfulAPIError $error)
    {
        $answer = new HTTPResponse();

        $body = $this->serializer->serialize($error->body);
        $answer->setBody($body);

        $answer->setStatusCode($error->code, $error->message);
        $answer->addHeader('Content-Type', $this->serializer->getcontentType());

        $answer = $this->setAnswerCORS($answer);

        // save controller's response then return/output
        $this->response = $answer;

        return $answer;
    }
8608
public function decorateException($error)
    {
        $application = $this->application;

        if (is_callable($error)) {
            $error = $application->getContainer()->call($error, [$application]);
        }

        if (is_object($error) && !($error instanceof \Exception)) {
            $error = method_exists($error,
                '__toString') ? $error->__toString() : 'Error with object ' . get_class($error);
        }

        if (is_resource($error)) {
            $error = 'Error with resource type ' . get_resource_type($error);
        }

        if (is_array($error)) {
            $error = implode("\n", $error);
        }

        if (!($error instanceof \Exception)) {
            $error = new \Exception(is_scalar($error) ? $error : 'Error with ' . gettype($error));
        }

        return $error;
    }
681134
public function prepare(Exception $exception)
  {
    if ($exception instanceof NotFoundHttpException) {
      return $exception->createsClientError();
    } else if ($exception instanceof ServiceUnavailableHttpException) {
      return $exception->createsServerError();
    }

    return $exception;
  }
274022
public function response(array $errors)
    {
        if (($this->ajax() && ! $this->pjax()) || $this->wantsJson()) {
            return new JsonResponse($errors, ValidationException::VALIDATION_FAILED);
        }

        return $this->redirector->to($this->getRedirectUrl())
            ->withInput($this->except($this->dontFlash))
            // This makes errors display properly (original errors are placed under the key 'errors' instead of 'error')
            ->with('error', $this->getValidatorInstance()->getMessageBag());
    }