@param \Exception|\Throwable $exception
@param Message               $message
@param array                 $options

@return mixed
346694
private function handleException($exception, Message $message, array $options)
    {
        $headers = $message->getProperties();
        if (isset($headers['headers']['x-death'])) {
            $xDeathHeaders = $headers['headers']['x-death'];
            // PhpAmqpLib compatibility
            if ($xDeathHeaders instanceof AMQPArray) {
                $xDeathHeaders = $headers['headers']['x-death']->getNativeData();
            }

            $queueXDeathHeader = null;
            foreach ($xDeathHeaders as $xDeathHeader) {
                if (isset($xDeathHeader['queue']) && $xDeathHeader['queue'] === $this->queueName) {
                    $queueXDeathHeader = $xDeathHeader;
                    break;
                }
            }

            if (null === $queueXDeathHeader) {
                $this->logException(
                    $exception,
                    sprintf(
                        '[XDeathMaxLifetime] No x-death header found for queue name "%s". Do nothing.',
                        $this->queueName
                    ),
                    $options['x_death_max_lifetime_fail_log_levels_map']
                );
            } elseif (isset($queueXDeathHeader['time'])) {
                $xDeathTimestamp = $queueXDeathHeader['time'];
                if ($xDeathTimestamp instanceof \DateTime || $xDeathTimestamp instanceof \AMQPTimestamp) {
                    $xDeathTimestamp = $xDeathTimestamp->getTimestamp();
                }
                $remainLifetime = $xDeathTimestamp - (time() - $options['x_death_max_lifetime']);
                if ($remainLifetime <= 0) {
                    $this->logException(
                        $exception,
                        sprintf(
                            '[XDeathMaxLifetime] Max lifetime reached. %s/%s seconds exceed. Execute the configured callback.',
                            abs($remainLifetime),
                            $options['x_death_max_lifetime']
                        ),
                        $options['x_death_max_lifetime_fail_log_levels_map']
                    );

                    if (null !== $return = \call_user_func($this->callback, $exception, $message, $options)) {
                        return $return;
                    }
                } else {
                    $this->logException(
                        $exception,
                        sprintf(
                            '[XDeathMaxLifetime] Lifetime remain %d/%d seconds.',
                            $remainLifetime,
                            $options['x_death_max_lifetime']
                        ),
                        $options['x_death_max_lifetime_log_levels_map']
                    );
                }
            }
        }

        throw $exception;
    }
886269
public function handle(Exception $exception, ServerRequestInterface $request, ResponseInterface $response, array $options = [])
    {
        $options += $this->defaultOptions;

        if (!$this->checkException($exception, $options['exceptions'])) {
            throw $exception;
        }

        $url = $this->getUrl($request, $options);

        return $response
                ->withHeader('Location', $url)
                ->withStatus($options['statusCode']);
    }
436773
public function logError(Exception $exception, $message = '')
    {
        if (empty($message)) {
            $message = $exception->getMessage();
        }

        array_push($this->store, array(
            'data' => $message,
            'file' => $exception->getFile(),
            'line' => $exception->getLine(),
            'type' => 'error'
        ));
    }
1059850
public function send($message, array $options = [])
    {
        $sms = new Message($options);
        $this->request('sms', $sms->getParams());
        $response = $this->getResponse();

        if ($response['error_code'] !== '000') {
            $this->errors[] = $response['error_code'];
            return false;
        }

        return true;
    }
493655
public function deserialize($data, Message $message, array $options = [])
    {
        $this->sipe('object', 'setObject', $data, $message);
        $this->sipe('content', 'setContent', $data, $message);
        $currentUser = $this->tokenStorage->getToken()->getUser();

        if (isset($data['parent'])) {
            $parent = $this->om->getRepository(Message::class)->find($data['parent']['id']);
            $message->setParent($parent);
        }

        if ($currentUser instanceof User && in_array(Options::CRUD_CREATE, $options)) {
            $message->setSender($currentUser);
        }

        //build the "to" string here
        //; is the separator
        //{} for groups
        //[] for workspaces
        $receivers = [];

        if (isset($data['toGroups'])) {
            $receivers = array_merge(array_map(function ($group) {
                return '{'.$group['name'].'}';
            }, $data['toGroups']), $receivers);
        }

        if (isset($data['toUsers'])) {
            $receivers = array_merge(array_map(function ($user) {
                return $user['username'];
            }, $data['toUsers']), $receivers);
        }

        if (isset($data['toWorkspaces'])) {
            $receivers = array_merge(array_map(function ($workspace) {
                return '['.$workspace['code'].']';
            }, $data['toWorkspaces']), $receivers);
        }

        $receiversString = implode(';', $receivers);

        if ('' !== $receiversString && !$message->getTo()) {
            $message->setTo($receiversString);
        }

        return $message;
    }
1233366
private function handleException(Envelope $envelope, Request $request, Message $message, \Throwable $exception): Envelope
    {
        if ($exception instanceof HasEndUserMessage) {
            $code = $exception->getCode();
            $httpCode = StatusCodeConverter::vendorToHttp($code);
            $errorName = ClassUtils::getShortName($exception);
            $errorMessage = $exception->getEndUserMessage();
            $request->attributes->set('pbjx_redact_error_message', false);
        } elseif ($exception instanceof HttpExceptionInterface) {
            $code = StatusCodeConverter::httpToVendor($exception->getStatusCode());
            $httpCode = $exception->getStatusCode();
            $errorName = ClassUtils::getShortName($exception);
            $errorMessage = $exception->getMessage();
        } elseif ($exception instanceof RequestHandlingFailed) {
            $response = $exception->getResponse();
            $code = $response->get('error_code', Code::UNKNOWN);
            $httpCode = StatusCodeConverter::vendorToHttp($code);
            $errorName = $response->get('error_name', ClassUtils::getShortName($exception));
            $errorMessage = $response->get('error_message', $exception->getMessage());
        } elseif ($exception instanceof GdbotsPbjException) {
            $code = Code::INVALID_ARGUMENT;
            $httpCode = HttpCode::HTTP_UNPROCESSABLE_ENTITY;
            $errorName = ClassUtils::getShortName($exception);
            $errorMessage = $exception->getMessage();
            // these error messages are safe to show as they only indicate schema problems
            $request->attributes->set('pbjx_redact_error_message', false);
        } else {
            $code = $exception->getCode() > 0 ? $exception->getCode() : Code::INVALID_ARGUMENT;
            $httpCode = StatusCodeConverter::vendorToHttp($code);
            $errorName = ClassUtils::getShortName($exception);
            $errorMessage = $exception->getMessage();
        }

        return $envelope
            ->set('code', $code)
            ->set('http_code', HttpCode::create($httpCode))
            ->set('error_name', $errorName)
            ->set('error_message', $errorMessage);
    }
45173
public static function errorLog(string $message, \Exception $exception)
    {
        $logger = Config::getLogger();
        if ($logger) {
            $logger->error($message, ['exception' => $exception]);
        }
    }
270054
public function startInfo($message, array $options = null) {
		return $this->startEvent($message, ProfileInterface::TYPE_INFO, $options);
	}
14296
public function logFailure($message, \Exception $exception = null)
    {
        $context = array();

        // The psr3 log interface stipulates that exceptions should be passed
        // as the exception key in the context array.
        if ($exception) {
            $context['exception'] = $exception;
        }

        $this->log(
            "\033[0;31m" . $message . "\033[0m",
            LogLevel::ERROR,
            $context
        );
    }
5470
public static function parse($message, $options = [])
    {
        $parts = explode("\r\n\r\n", $message, 2);
        if (count($parts) < 2) {
            throw new NetException("The CRLFCRLF separator between headers and body is missing.");
        }
        $response = new static($options + ['format' => null]);

        list($header, $body) = $parts;

        $data = str_replace("\r", '', explode("\n", $header));
        $data = array_filter($data);

        preg_match('/HTTP\/(\d+\.\d+)\s+(\d+)(?:\s+(.*))?/i', array_shift($data), $matches);

        $headers = $response->headers();
        $headers->push($data);

        if ($matches) {
            $response->version($matches[1]);
            $response->status([$matches[2], isset($matches[3]) ? $matches[3] : '']);
        }

        if ($headers['Transfer-Encoding']->value() === 'chunked') {
            $decoded = '';
            while (!empty($body)) {
                $pos = strpos($body, "\r\n");
                $len = hexdec(substr($body, 0, $pos));
                $decoded .= substr($body, $pos + 2, $len);
                $body = substr($body, $pos + 2 + $len);
            }
            $body = $decoded;
        }

        $response->body($body);
        return $response;
    }
823269
public function getException($message)
    {
        // make exception based on the status code
        switch ($this->statusCode) {
            case 400:
                return
                    $message?
                        new PlivoValidationException($message):
                        new PlivoValidationException(
                            "A parameter is missing or ".
                            "is invalid while accessing resource");
                break;
            case 401:
                return
                    $message?
                        new PlivoAuthenticationException($message):
                        new PlivoAuthenticationException(
                        "Failed to authenticate while accessing resource");
                break;
            case 404:
                return
                    $message?
                        new PlivoNotFoundException($message):
                        new PlivoNotFoundException(
                        "Failed to authenticate while accessing resource");
                break;
            case 405:
                return
                    $message?
                        new PlivoRequestException($message):
                        new PlivoRequestException(
                        "HTTP method used is not allowed to access resource");
                break;
            case 500:
                return
                    $message?
                        new PlivoServerException($message):
                        new PlivoServerException(
                        "A server error occurred while accessing resource");
                break;
            default:
                return new PlivoRestException(json_encode($this->responseData));
        }

    }
854798
public function serialize(AbstractMessage $message, array $options = [])
    {
        return [
            'id' => $message->getUuid(),
            'content' => $message->getContent(),
            'meta' => $this->serializeMeta($message),
            'parent' => $this->serializeParent($message),
            'children' => array_map(function (AbstractMessage $child) use ($options) {
                return $this->serialize($child, $options);
            }, $message->getChildren()->toArray()),
        ];
    }
1332058
public function notify($exception, $options = array()) {
		$config = array_merge($this->_config, $options);

		$ch = curl_init();
		curl_setopt_array($ch, array(
			CURLOPT_URL            => $this->_buildApiUrl(),
			CURLOPT_HEADER         => true,
			CURLOPT_POST           => true,
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_POSTFIELDS     => $this->_buildNoticeFor($exception, $config),
			CURLOPT_HTTPHEADER     => array(
				'Content-Type: text/xml',
				'Accept: text/xml, application/xml'
			)
		));
		curl_exec($ch);

		foreach ($this->_observers as $observer) {
			$observer($exception, $config);
		}

		return $this;
	}
971308
protected function encodeMessage($message, array $options = [])
    {
        $resolver = new OptionsResolver();
        $this->encoder->setDefaultOptions($resolver);
        $options = $resolver->resolve($options);

        return $this->encoder->encode($message, $this->compressor, $options);
    }
1251056
public function addTransientMessage($message, $options = null) {
		$options = $this->_mergeOptions($options);
		$options['message'] = $message;

		$messages = (array)Configure::read('TransientFlash.' . $options['key']);
		if ($messages && count($messages) > $this->getConfig('limit')) {
			array_shift($messages);
		}
		$messages[] = $options;
		Configure::write('TransientFlash.' . $options['key'], $messages);
	}
565308
public function addRule($field, $rule, $message, $options = array()) {
        if (empty($this->_fields[$field])) {
            throw new InvalidArgumentException(sprintf('Field %s does not exist', $field));
        }

        if (isset($this->_messages[$rule])) {
            $message = $message ?: $this->_messages[$rule];
        } else {
            $this->_messages[$rule] = $message;
        }

        $this->_rules[$field][$rule] = array(
            'message' => $message,
            'options' => (array) $options
        );

        return $this;
    }
909255
private function logException($message, $exception)
    {
        return $this->app['logger.system']->error(
            $message . ': ' . $exception->getMessage(),
            ['event' => 'exception', 'exception' => $exception]
        );
    }