Send a HTTP response for an exception

@param \Akkroo\APIClient\Exceptions\WebHookHandlerException $e
@return static
502971
public function sendExceptionResponse(WebHookHandlerException $e) {
		$httpCode = '400 Bad Request';
		switch($e->getCode()) {
			case WebHookHandlerException::NO_PRIVATE_KEY:
				$httpCode = '500 Internal Server Error';
				break;
			case WebHookHandlerException::INVALID_DECRYPTED_JSON:
			case WebHookHandlerException::DECRYPTION_FAILED:
			case WebHookHandlerException::INPUT_FETCH_FAILED:
			case WebHookHandlerException::INPUT_DECODE_FAILED:
			case WebHookHandlerException::NO_ENVELOPE_KEY:
			case WebHookHandlerException::NO_PAYLOAD:
			case WebHookHandlerException::NO_INPUT_HASH:
				$httpCode = '400 Bad Request';
				break;
		}
		$this->sendHTTPResponse($httpCode, ['success' => false, 'errorCode' => $e->getCode(), 'errorDescription' => $e->getMessage()]);
		return $this;
	}
986584
protected function createErrorPage(\Throwable $e){
        $response   = $this->factory->createResponse(
            $e instanceof HttpStatus ? $e->getStatusCode() : 500
        );

        if($e instanceof \Fratily\Http\Message\Status\MethodNotAllowed){
            $response   = $response->withHeader(
                "Allow",
                implode(", ", $e->getAllowed())
            );
        }

        return $response;
    }
339521
protected function handleException($passable, Exception $e)
    {
        if (! $this->container->bound(ExceptionHandler::class) ||
            ! $passable instanceof Request) {
            throw $e;
        }

        $handler = $this->container->make(ExceptionHandler::class);

        $handler->report($e);

        $response = $handler->render($passable, $e);

        if (method_exists($response, 'withException')) {
            $response->withException($e);
        }

        return $response;
    }
397084
protected function convertExceptionToResponse(Exception $e)
    {
        $e = FlattenException::create($e);

        $handler = new SymfonyExceptionHandler(config('app.debug'));

        $decorated = $this->decorate($handler->getContent($e), $handler->getStylesheet($e));

        return SymfonyResponse::create($decorated, $e->getStatusCode(), $e->getHeaders());
    }
292029
protected function editActionException(\Exception $e)
    {
        $this->handleException($e);
        $id = $this->get('request')->get($this->admin->getIdParameter());
        $object = $this->admin->getObject($id);

        return $this->redirectTo($object);
    }
643827
static function exceptionHandler($e) {
	    if(get_class($e) == 'PDOException'){
	        $err = $e->getMessage().'<br>code: '.$e->getCode();
	    } else {
	        $err = 
	        '<b>Code:</b>'.$e->getCode().'<br>'.
	        '<b>Message:</b> <i>'.$e->getMessage().'</i><br>'.
	        '<b>Thrown in: </b>'.$e->getFile().' ['.$e->getLine().']<br>'.
	        '<b>Stack trace:</b><pre>'.$e->getTraceAsString().'</pre>';
	        
	    }
	    exit($err);
	}
486490
protected function getExceptionResponse($e) {
		while(ob_get_level() > $this->startObLevel)
			ob_end_clean();

		$this->errorHandler->exceptionHandler($e);

		$trace = $this->errorHandler->getBacktraceFromException($e);

		if($e instanceof \Asgard\Debug\PSRException)
			$msg = $e->getMessage();
		elseif($e instanceof \ErrorException)
			$msg = 'PHP ('.$this->errorHandler->getPHPError($e->getCode()).'): '.$e->getMessage();
		else
			$msg = get_class($e).': '.$e->getMessage();

		$result = '<b>Message</b><br>'."\n"
			. $msg."<hr>\n"
			. \Asgard\Debug\Debug::getReport($trace);

		$response = new \Asgard\Http\Response(500);
		if($this->debug)
			return $response->setHeader('Content-Type', 'text/html')->setContent($result);
		else {
			$msg = isset($this->translator) ? $this->translator->trans('<h1>Error</h1>Oops, something went wrong.'):'<h1>Error</h1>Oops, something went wrong.';
			return $response->setHeader('Content-Type', 'text/html')->setContent($msg);
		}
	}
1152111
protected function prepareResponse($request, Exception $e)
    {
        if (! $this->isHttpException($e) && config('app.debug')) {
            return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e);
        }

        if (! $this->isHttpException($e)) {
            $e = new HttpException(500, $e->getMessage());
        }

        return $this->toIlluminateResponse(
            $this->renderHttpException($e), $e
        );
    }
215871
protected function convertExceptionToResponse(Exception $e)
    {
        return SymfonyResponse::create(
            $this->renderExceptionContent($e),
            $this->isHttpException($e) ? $e->getStatusCode() : 500,
            $this->isHttpException($e) ? $e->getHeaders() : []
        );
    }
100190
protected function notFound(NotFoundException $e)
    {
        if (isset($this->hooks['not.found'])) {
            return $this->hooks['not.found']($e);
        } else {
            return (new Response())
                ->setStatusCode(404)
                ->setBody($e->getMessage());
        }
    }
1002705
public function handleException(\Throwable $e)
	{
        // headers sent by browser are prefixed with 'HTTP' (so that they don't mess with environment variables), and - are replaced by _
        if ( (strpos($_SERVER['HTTP_USER_AGENT'], 'XMLHTTP') === 0) || (strpos($_SERVER['HTTP_ACCEPT'], 'application/json') === 0) )
            // if XMLHTTP request
            $this->_handleXMLHTTPCommandException($e);

        // if GET/POST request
        else
            $this->_handleGETPOSTException($e);
        
        die();
    }
896310
public static function fromException(\Exception $e)
    {
        if ($e instanceof XsollaWebhookException) {
            return static::fromErrorCode($e->getXsollaErrorCode(), $e->getMessage(), $e->getHttpStatusCode());
        } else {
            return static::fromErrorCode('FATAL_ERROR', $e->getMessage());
        }
    }
52461
protected function getErrorResponse(Exception $e)
    {
        switch (get_class($e)) {
            case ForbiddenException::class:
                $response = $this->forbidden(
                    new ErrorBag([new Error('Forbidden', $e->getMessage())])
                );
                break;
            default:
                $response = $this->errorResponse(
                    new ErrorBag([new Error('Bad Request', 'Request could not be served.')])
                );
        }

        return $response;
    }
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;
	}
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);
    }
319733
protected function renderXmlHttpException($e)
    {
        // handle our ajax errors
        $data = [
            'message' => $e->getMessage(),
        ];

        if ($e instanceof HttpException) {
            return new JsonResponse($data, $e->getStatusCode());
        }

        return new JsonResponse($data, 500);
    }
1285459
private function _exceptionHandler($e)
    {
        $this->_errorController->setParams(array('e' => $e));
        $action = FrontController::EXCEPTION_HANDLER_ACTION . 'Action';
        $this->_response->setStatusCode(500);

        return $this->_errorController->$action();
    }