/** * @param \use Piece\Questetra\Core\ServiceException $e * @return \Piece\Questetra\API\TaskExecutionException * @throws \UnexpectedValueException */ protected function createTaskExecutionException(ServiceException $serviceException) { $data = $this->parseXMLResponse($serviceException->getResponse()); $processDataValidationErrors = array(); foreach ($data->xpath('//process-data-validation-errors/error') as $error) { $processDataValidationErrors[(string) $error->key] = (string) $error->detail; } $errors = array(); foreach ($data->xpath('//errors/error') as $error) { $errors[(string) $error->key] = (string) $error->detail; } $taskExecutionException = new TaskExecutionException($serviceException->getMessage()); $taskExecutionException->setRequestContext($serviceException->getRequestContext()); $taskExecutionException->setRequest($serviceException->getRequest()); $taskExecutionException->setResponse($serviceException->getResponse()); $taskExecutionException->setProcessDataValidationErrors($processDataValidationErrors); $taskExecutionException->setErrors($errors); return $taskExecutionException; }
/** * @param \use Piece\Questetra\Core\ServiceException $e * @return \Piece\Questetra\API\ErrorResponseException * @throws \UnexpectedValueException */ protected function createErrorResponseException(ServiceException $serviceException) { $data = $this->parseJSON($serviceException->getResponse()); if (!array_key_exists('errors', $data)) { throw new \UnexpectedValueException(sprintf("The key 'errors' is not found in the data that is returned from [ %s ].", $serviceException->getRequest()->getUrl())); } if (!is_array($data['errors'])) { throw new \UnexpectedValueException("The value of the key 'errors' is not an array."); } $errors = array(); foreach ($data['errors'] as $error) { $errorEntry = new ErrorEntry(); $this->transformToObject($error, $errorEntry); $errors[] = $errorEntry; } $errorResponseException = new ErrorResponseException($serviceException->getMessage()); $errorResponseException->setRequestContext($serviceException->getRequestContext()); $errorResponseException->setRequest($serviceException->getRequest()); $errorResponseException->setResponse($serviceException->getResponse()); $errorResponseException->setErrors($errors); return $errorResponseException; }