Handles http client exceptions.

@param    HttpClientException $e

@return   void
@throws   Exception
166495
private function handleRequestException(HttpClientException $e)
    {
        if ($response = $e->getResponse()) {
            $exception = new Exception($response->getReasonPhrase(), $response->getStatusCode(), $e);
            $exception->setBody(json_decode($response->getBody()));

            throw $exception;
        }

        throw new Exception($e->getMessage(), 500, $e);
    }
610869
public function handle($exception)
    {
        $exception = call_user_func($this->config('exceptionCallback'), $exception);
        if (!$exception) {
            return;
        }
        $client = $this->client();
        $client = call_user_func($this->config('clientCallback'), $client);
        if ($client) {
            $client->captureException($exception);
        }
    }
844262
protected function handleException($request, Exception $e)
    {
        $handler = $this->app->make(ExceptionHandler::class);

        return $handler->render($request, $e);
    }
1002333
protected function handleApiException(ClientException $e, Project $project)
    {
        $response = $e->getResponse();
        if ($response !== null && $response->getStatusCode() === 403) {
            $project->ensureFull();
            $data = $project->getData();
            if (!$project->hasLink('#manage-domains')
                && !empty($data['subscription']['plan'])
                && $data['subscription']['plan'] === 'development') {
                $this->stdErr->writeln('This project is on a Development plan. Upgrade the plan to add domains.');
            }
        } else {
            throw $e;
        }
    }
181296
public static function handle(CommunicationException $exception)
    {
        if ($exception->shouldResetConnection()) {
            $connection = $exception->getConnection();

            if ($connection->isConnected()) {
                $connection->disconnect();
            }
        }

        throw $exception;
    }
434039
protected function handleErrorResponses(HttpException $exception)
    {
        $status = $exception->getCode();
        $message = $exception->getStatusMessage();
        $solrRespone = new ResponseAdapter($exception->getBody());

        if ($status === 0 || $status === 502) {
            $e = new SolrUnavailableException('Solr Server not available: ' . $message, 1505989391);
            $e->setSolrResponse($solrRespone);
            throw $e;
        }

        if ($status === 500) {
            $e = new SolrInternalServerErrorException('Internal Server error during search: ' . $message, 1505989897);
            $e->setSolrResponse($solrRespone);
            throw $e;
        }

        $e = new SolrCommunicationException('Invalid query. Solr returned an error: ' . $status . ' ' . $message, 1293109870);
        $e->setSolrResponse($solrRespone);

        throw $e;
    }
658888
public static function handler (\Exception $e) {
    try {
      $project = PSC::getProject();
    } catch (\Exception $noProjet) {
      $project = NULL;
    }
    
    $format = PHP_SAPI === 'cli' ? 'text' : 'html';
    
    $text = self::getExceptionText($e, $format, $project);
    
    print $text;
    
    PSC::getEnvironment()->getErrorHandler()->handleCaughtException($e);
  }
454183
public function appException($e)
    {
        throw new ErrorException($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTrace());

    }
784080
public function handleException(\Exception $e)
	{
        $environment = $this->core->getCurrentDomain()->environment;
		
		if(isset($this->core->getSettings()->errorhandling->controller->$environment) === true) {
			$controller = FrameworkUtils::stringToClassName($this->core->getSettings()->errorhandling->controller->$environment);

			$pc = new $controller->className($this->core, $this->core->getHttpRequest(), new Route());

			$httpResponse = call_user_func(array($pc, $controller->methodName), $e);
		} else {
			$content = null;

			$httpErrorCode = ($e instanceof HttpException)?$e->getCode():500;
			$exceptionStr = null;

			if($this->core->getSettings()->core->environments->$environment->debug === true) {
				$exceptionStr = "\n<pre>";

				$exceptionStr .= '<b>Uncaught exception' . "\n" . '==================</b>' . "\n";
				$exceptionStr .= 'Type: ' . get_class($e) . "\n";
				$exceptionStr .= 'Message: ' . $e->getMessage() . ' (Code: ' . $e->getCode() . ')' . "\n";
				$exceptionStr .= 'Thrown in: ' . $e->getFile() . ' (Line: ' . $e->getLine() . ")\n\n";

				$exceptionStr .= $e->getTraceAsString();

				$exceptionStr .= '</pre>';
			}

			$errorStr = $httpErrorCode . ' ' . HttpResponse::getHttpStatusString($httpErrorCode);
			$content = "<!doctype html>\n<html>\n<head>\n<title>" . $errorStr . "</title>\n</head>\n<body>\n<h1>" . $errorStr . "</h1>" . $exceptionStr . "\n</body>\n</html>";

			$httpResponse = new HttpResponse($httpErrorCode, $content);
		}

		$httpResponse->send();

		exit;
	}
867985
protected function prepareException(Exception $e)
    {
        $e = parent::prepareException($e);

        if ($e instanceof MethodNotAllowedHttpException) {
            $e = new HttpException(405, 'Method not allowed', $e->getPrevious(), $e->getHeaders(), $e->getCode());
        }

        return $e;
    }
924965
public function handle($e)
	{
		$this->logException($e);

		if ($this->isExceptionHalting($e))
		{
			// if headers are sent, we can't send a response
			if(headers_sent())
			{
				echo $this->buildResponseBody($e);
				exit(0);
			}

			// send it off
			$sender = new Http\ResponseSender($this->buildResponse($e));
			$sender->send();

			if (ob_get_level() > 0) ob_flush();
			exit(self::EXIT_CODE);
		}
	}
983710
public function handleException($exception)
    {
        $isHandled = false;
        try {
            $isHandled = $this->handler->handle($exception);
        } catch (Exception $ex) {
        } catch (Throwable $ex) {
        }

        // Bomb out if handler returns true, since was able to render something to the client
        if ($isHandled) {
            exit;
        }

        // Rethrow to be handled by default php exception handling.
        throw $exception;
    }
125067
private function handleException(\Exception $exception)
    {
        // Any exception means the client send has failed.
        $this->valid = false;

        if ($exception instanceof ContactClientException) {
            // A known exception within the Client handling.
            if ($this->contact) {
                $exception->setContact($this->contact);
            }

            // Handle retryable / queue exceptions.
            if (
                Stat::TYPE_SCHEDULE == $exception->getStatType()
                && $this->contactClient
                && 'api' == $this->contactClient->getType()
                && $this->contactClient->getScheduleQueue()
            ) {
                // API request during a closed hour/day but the queue is enabled for this.
                // Attempt to reschedule given the spread setting and scheduling.
                $maxDay    = $this->contactClient->getScheduleQueueSpread();
                $startTime = new \DateTime('+1 hour');
                if ($this->addRescheduleItemToSession(0, $maxDay, $startTime, $exception->getMessage())) {
                    // Requeue the contact to be sent at a later time per API Schedule Queue setting,
                    $this->retry = true;
                    $exception->setStatType(Stat::TYPE_SCHEDULE_QUEUE);
                    $exception->setMessage($exception->getMessage().' Queued for a later.');
                }
            } elseif (
                Stat::TYPE_LIMITS == $exception->getStatType()
                && $this->contactClient
                && $this->contactClient->getLimitsQueue()
            ) {
                // Rate limits were exceed but the queue is enabled for this.
                // Attempt to reschedule given the spread setting and scheduling.
                $maxDay = $this->contactClient->getLimitsQueueSpread();
                if ($this->addRescheduleItemToSession(1, $maxDay, null, $exception->getMessage())) {
                    // Requeue the contact to be sent at a later time per Limits Queue setting,
                    $this->retry = true;
                    $exception->setStatType(Stat::TYPE_LIMITS_QUEUE);
                    $exception->setMessage($exception->getMessage().' Queued for a later.');
                }
            } elseif (
                $exception->getRetry()
                && $this->contactClient
                && 'api' === $this->contactClient->getType()
                && ($payloadModel = $this->getPayloadModel())
                && ($settings = $payloadModel->getSettings())
                && isset($settings['autoRetry'])
                && true === boolval($settings['autoRetry'])
            ) {
                // API based client had a retryable exception and has autoRetry enabled, so we should retry if possible.
                // Attempt to reschedule to the next open slot by global campaign setting up to 1 day in the future.
                // This will avoid retries on closed hours if at-all possible.
                /** @var string $intervalString */
                $intervalString = $this->getParameterHelper()->getParameter(
                    'campaign_time_wait_on_event_false'
                );
                if ($intervalString) {
                    try {
                        $interval  = new \DateInterval($intervalString);
                        $startTime = new \DateTime();
                        $startTime->add($interval);
                    } catch (\Exception $e) {
                        // If no interval is set default to a few hours in the future
                        $startTime = new \DateTime('+6 hours');
                    }
                    // Add randomized drift of up to 30 minutes to reduce likelihood of stampedes.
                    $startTime->modify('+'.rand(0, 1800).' seconds');
                    if ($this->addRescheduleItemToSession(0, 1, $startTime, $exception->getMessage())) {
                        $this->retry = true;
                    }
                }
            }

            // We will persist exception information to logs/stats.
            if ($exception->getStatType()) {
                $this->statType = $exception->getStatType();
                $this->setLogs($this->statType, 'status');
            }
            $errorData = $exception->getData();
            if ($errorData) {
                $this->setLogs($errorData, $exception->getStatType());
            }
        } elseif ($exception instanceof ConnectException) {
            if (function_exists('newrelic_notice_error')) {
                call_user_func(
                    'newrelic_notice_error',
                    'ContactClient Connection Error '.($this->contactClient ? $this->contactClient->getId() : 'NA'),
                    $exception
                );
            }
        } else {
            if (function_exists('newrelic_notice_error')) {
                call_user_func(
                    'newrelic_notice_error',
                    'ContactClient Integration Error '.($this->contactClient ? $this->contactClient->getId() : 'NA'),
                    $exception
                );
            }
            // Unexpected issue with the Client plugin.
            $this->logIntegrationError($exception, $this->contact);
        }
        $this->setLogs($exception->getMessage(), 'error');
        $this->setLogs($this->retry, 'retry');
    }
488304
public function report(Exception $e)
    {
        logger()->error('PHP Error', [
            'file'    => $e->getFile(),
            'line'    => $e->getLine(),
            'message' => $e->getMessage()
        ]);
    }
1321105
public function handleException($e)
    {
        if (!$e instanceof Exception) {
            $e = new FatalThrowableError($e);
        }

        $this->getExceptionRenderer()->render($e, $this->debug());
    }
864800
private function _throwServerError(\Exception $e) {
		$uri = (string) $this->httpClient->getConfig('base_uri');

		throw new ServerErrorHttpException(get_class($e).': url='.$uri .' '. $e->getMessage(), 500);
	}
966526
protected function _handleProcessException(Exception $e)
    {
        if ($e instanceof Kwf_Exception_Client) {
            $this->_errors[] = array(
                'message' => $e->getMessage()
            );
        } else {
            if (!$e instanceof Kwf_Exception) $e = new Kwf_Exception_Other($e);
            $e->logOrThrow();
            $this->_errors[] = array(
                'message' => trlKwf('An error occured while processing the form. Please try to submit again later.')
            );
        }
    }