Exemplo n.º 1
0
 /**
  * @param \Exception $exception
  * @param WorkflowMessage|TaskListPosition $originMessageOrTaskListPosition
  * @throws \InvalidArgumentException
  * @return LogMessage
  */
 public static function logException(\Exception $exception, $originMessageOrTaskListPosition)
 {
     $errorCode = $exception->getCode() ?: self::ERROR_SYSTEM_ERROR;
     if ($errorCode < 400) {
         $errorCode = self::ERROR_SYSTEM_ERROR;
     }
     $origin = null;
     $taskListPosition = null;
     if ($originMessageOrTaskListPosition instanceof WorkflowMessage) {
         $origin = $originMessageOrTaskListPosition->target();
         $taskListPosition = $originMessageOrTaskListPosition->processTaskListPosition();
     } elseif ($originMessageOrTaskListPosition instanceof TaskListPosition) {
         $origin = $originMessageOrTaskListPosition->taskListId()->nodeName()->toString();
         $taskListPosition = $originMessageOrTaskListPosition;
     } else {
         throw new \InvalidArgumentException("Second param of LogMessage::logException should be a workflow message or task list position. Got:  " . gettype($originMessageOrTaskListPosition));
     }
     return new self($origin, $taskListPosition, $exception->getMessage(), $errorCode, array(self::MSG_PARAM_TRACE => $exception->getTraceAsString()));
 }