/** * @return array */ public function toArray() { $return = []; if ($this->getReturnStatusCode()) { $return['statusCode'] = $this->getStatusCode(); } if (isset($this->exception)) { if ($this->exception instanceof FormValidationException) { $error = $this->exception->toArray(); } elseif ($this->exception instanceof HttpException) { $error = ['code' => self::ERROR_HTTP_PREFIX . StringUtil::classToSnakeCase($this->exception, 'HttpException'), 'message' => $this->exception->getMessage()]; } else { $error = ['code' => trim(self::ERROR_GENERAL_PREFIX . StringUtil::classToSnakeCase($this->exception, 'Exception'), '.'), 'message' => $this->exception->getMessage()]; } $return['error'] = $error; } if (isset($this->data)) { $return['data'] = $this->data; } if (isset($this->location)) { $return['location'] = $this->location; } if (isset($this->pagination)) { $return['pagination'] = $this->pagination; } return $return; }
/** * @return array */ protected function exceptionToArray() { if ($this->exception instanceof ExceptionInterface) { $error = $this->exception->toArray(); } elseif ($this->exception instanceof HttpException) { $error = $this->httpExceptionToArray(); } else { $error = $this->generalExceptionToArray(); } if ($this->isReturnStackTrace()) { $error['stack_trace'] = $this->getExceptionStackTrace(); } return $error; }
/** * Formats and returns * @param null $result * @param \JsonRpc2\Exception|null $error * @param null $id * @return array */ public static function formatResponse($result = null, Exception $error = null, $id = null) { $resultKey = 'result'; if (!empty($error)) { $resultKey = 'error'; $resultValue = $error->toArray(); } else { if (null === $result) { $resultValue = self::$defaultResult; } else { $resultValue = $result; } } return ['jsonrpc' => '2.0', $resultKey => $resultValue, 'id' => $id]; }
/** * Convert given exception to an array of scalar values. * * @param \Exception $e_ * @param bool $includeStackTrace_ * @param bool $stackTraceAsArray_ * * @return scalar[][] */ function exception_as_array(\Exception $e_, $includeStackTrace_ = false, $stackTraceAsArray_ = false) { if ($e_ instanceof \Components\Runtime_Exception_Transformable) { return $e_->toArray($includeStackTrace_, $stackTraceAsArray_); } $type = Components\Type::of($e_); $exceptionAsArray = ['id' => \math\hasho_md5($e_), 'type' => $type->name(), 'code' => $e_->getCode(), 'namespace' => $type->ns()->name(), 'message' => $e_->getMessage(), 'file' => $e_->getFile(), 'line' => $e_->getLine()]; if ($includeStackTrace_ && $stackTraceAsArray_) { $exceptionAsArray['stack'] = exception_stacktrace_as_array($e_); } else { if ($includeStackTrace_) { $exceptionAsArray['stack'] = $e_->getTraceAsString(); } } return $exceptionAsArray; }
/** * handle import exceptions * * @param Exception $_e * @param integer $_recordIndex * @param Tinebase_Record_Abstract|array $_record * * @todo use json converter for client record */ protected function _handleImportException(Exception $_e, $_recordIndex, $_record = NULL) { if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' ' . $_e->getMessage()); } if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $_e->getTraceAsString()); } if ($_e instanceof Tinebase_Exception_Duplicate) { $this->_importResult['duplicatecount']++; $exception = $_e->toArray(); } else { $this->_importResult['failcount']++; $exception = array('code' => $_e->getCode(), 'message' => $_e->getMessage(), 'clientRecord' => $_record !== NULL && $_record instanceof Tinebase_Record_Abstract ? $_record->toArray() : (is_array($_record) ? $_record : array())); } $this->_importResult['exceptions']->addRecord(new Tinebase_Model_ImportException(array('code' => $_e->getCode(), 'message' => $_e->getMessage(), 'exception' => $exception, 'index' => $_recordIndex))); }