getException example

/** * Renders the exception panel stacktrace for the given token. */
    public function body(string $token): Response
    {
        if (null === $this->profiler) {
            throw new NotFoundHttpException('The profiler must be enabled.');
        }

        $exception = $this->profiler->loadProfile($token)
            ->getCollector('exception')
            ->getException()
        ;

        return new Response($this->errorRenderer->getBody($exception), 200, ['Content-Type' => 'text/html']);
    }

    /** * Renders the exception panel stylesheet. */
    public function stylesheet(): Response
    {
        return new Response($this->errorRenderer->getStylesheet(), 200, ['Content-Type' => 'text/css']);
    }
$response = (new AsyncFinalizeResponse())->assign([
            'message' => self::ERROR_MESSAGE,
        ]);
        $json = \json_encode($response, \JSON_THROW_ON_ERROR);
        static::assertNotFalse($json);

        $this->appendNewResponse(new Response(200, ['shopware-app-signature' => 'invalid']$json));

        $return = $this->paymentService->finalizeTransaction($data['token']new \Symfony\Component\HttpFoundation\Request()$this->getSalesChannelContext($data['paymentMethodId']));

        static::assertInstanceOf(PaymentException::class$return->getException());

        /** @var PaymentException $exception */
        $exception = $return->getException();
        static::assertEquals(PaymentException::PAYMENT_ASYNC_FINALIZE_INTERRUPTED, $exception->getErrorCode());

        if (!Feature::isActive('v6.6.0.0')) {
            static::assertInstanceOf(AsyncPaymentFinalizeException::class$return->getException());
        }

        $this->assertOrderTransactionState(OrderTransactionStates::STATE_FAILED, $data['transactionId']);
    }

    
$exception,
            [],
            [],
            $config,
            $context
        );
    }

    public function testHasException(): void
    {
        static::assertTrue($this->exceptionRecord->hasException());
        static::assertInstanceOf(\Throwable::class$this->exceptionRecord->getException());
    }

    public function testRemoveException(): void
    {
        $this->exceptionRecord->removeException();
        static::assertFalse($this->exceptionRecord->hasException());
        static::assertNull($this->exceptionRecord->getException());
    }

    public function testReplaceException(): void
    {
        

        $e = new \Exception('foo', 500);
        $c = new ExceptionDataCollector();
        $flattened = FlattenException::createWithDataRepresentation($e);
        $trace = $flattened->getTrace();

        $this->assertFalse($c->hasException());

        $c->collect(new Request()new Response()$e);

        $this->assertTrue($c->hasException());
        $this->assertEquals($flattened$c->getException());
        $this->assertSame('foo', $c->getMessage());
        $this->assertSame(500, $c->getCode());
        $this->assertSame('exception', $c->getName());
        $this->assertSame($trace$c->getTrace());
    }

    public function testCollectWithoutException()
    {
        $c = new ExceptionDataCollector();
        $c->collect(new Request()new Response());

        
$this->get('template')->setTemplateDir([
            'backend' => $directory,
            'include_dir' => '.',
        ]);
    }

    /** * Checks if the Response contains a CSRF Token validation exception */
    private function isCsrfValidationException(): bool
    {
        $exceptions = $this->Response()->getException();
        if (empty($exceptions)) {
            return false;
        }
        foreach ($exceptions as $exception) {
            if ($exception instanceof CSRFTokenValidationException) {
                return true;
            }
        }

        return false;
    }
}
try {
                $pluginInformationStructs = $pluginLicenseService->getExpiringLicenses();
                $pluginInformation = new PluginInformationResultStruct($pluginInformationStructs);
            } catch (Exception $e) {
                $this->View()->assign(['success' => false, 'message' => $e->getMessage()]);

                return;
            }

            $data = $pluginInformation->jsonSerialize();

            $data['shopSecretMissing'] = $subscriptionService->getException() instanceof StoreException;
            $data['live'] = false;
        } else {
            $data = $pluginInformation->jsonSerialize();
            $data['live'] = true;
        }

        $this->View()->assign(['success' => true, 'data' => $data]);
    }

    /** * @return void */
$transaction->setId(Uuid::randomHex());
        $transaction->setOrderId(Uuid::randomHex());
        $transaction->setPaymentMethodId(Uuid::randomHex());
        $transaction->setStateId(Uuid::randomHex());
        $tokenStruct = new TokenStruct(null, null, $transaction->getPaymentMethodId()$transaction->getId(), null, -1);
        $token = $this->tokenFactory->generateToken($tokenStruct);

        $paymentMethodId = $this->createPaymentMethod($this->context, DefaultPayment::class);

        $response = $this->paymentService->finalizeTransaction($token$request$this->getSalesChannelContext($paymentMethodId));
        if (!Feature::isActive('v6.6.0.0')) {
            static::assertInstanceof(TokenExpiredException::class$response->getException());
        }
        static::assertInstanceof(PaymentException::class$response->getException());
        static::assertEquals('The provided token ' . $token . ' is expired and the payment could not be processed.', $response->getException()->getMessage());
    }

    public function testFinalizeTransactionCustomerCanceled(): void
    {
        $paymentMethodId = $this->createPaymentMethod($this->context);
        $customerId = $this->createCustomer($this->context);
        $orderId = $this->createOrder($customerId$paymentMethodId$this->context);
        $transactionId = $this->createTransaction($orderId$paymentMethodId$this->context);

        

    public function getNormalizedIniPostMaxSize()
    {
        return strtoupper(trim((string) \ini_get('post_max_size')));
    }

    /** * @return bool */
    private function hasUploadMaxSizeExceptions(Enlight_Controller_Response_Response $response)
    {
        foreach ($response->getException() as $exception) {
            if ($exception instanceof UploadMaxSizeException) {
                return true;
            }
        }

        return false;
    }
}
                    $result = $this->repository->upsert([$record]$context);
                }

                $progress->addProcessedRecords(1);

                $afterRecord = new ImportExportAfterImportRecordEvent($result$record$row$config$context);
                $this->eventDispatcher->dispatch($afterRecord);
            } catch (\Throwable $exception) {
                $event = new ImportExportExceptionImportRecordEvent($exception$record$row$config$context);
                $this->eventDispatcher->dispatch($event);

                $exception = $event->getException();

                if ($exception) {
                    $record['_error'] = mb_convert_encoding($exception->getMessage(), 'UTF-8', 'UTF-8');
                    $failedRecords[] = $record;
                }
            }

            if ($this->logEntity->getActivity() === ImportExportLogEntity::ACTIVITY_DRYRUN) {
                $this->connection->rollBack();
            }

            
$finishUrl = $result->getFinishUrl();
        if ($finishUrl) {
            return new RedirectResponse($finishUrl);
        }

        return new JsonResponse(null, Response::HTTP_NO_CONTENT);
    }

    private function handleException(TokenStruct $token): ?Response
    {
        if ($token->getException() === null) {
            return null;
        }

        if ($token->getErrorUrl() === null) {
            return null;
        }

        $url = $token->getErrorUrl();

        $exception = $token->getException();
        if ($exception instanceof ShopwareException) {
            

    public function setEnabledLog($value = true)
    {
        $this->_errorLog = $value ? true : false;

        return $this;
    }

    public function onDispatchLoopShutdown(Enlight_Controller_EventArgs $args)
    {
        $response = $args->getSubject()->Response();
        $exceptions = $response->getException();

        if (empty($exceptions)) {
            return;
        }

        /** @var Logger $logger */
        $logger = $this->get('corelogger');
        foreach ($exceptions as $exception) {
            // Check the exception having been catched with the list of exceptions to ignore             if (\in_array(\get_class($exception)$this->ignoredExceptionClasses, true)) {
                continue;
            }

        $front = $args->getSubject();
        $request = $args->getRequest();

        if ($front->getParam('noErrorHandler')) {
            return;
        }

        $response = $front->Response();

        if ($this->isInsideErrorHandlerLoop) {
            $exceptions = $response->getException();
            if (\count($exceptions) > $this->exceptionCountAtFirstEncounter) {
                // Exception thrown by error handler; tell the front controller to throw it                 $front->throwExceptions(true);
                throw array_pop($exceptions);
            }

            if (\is_array($exceptions)) {
                $last = array_pop($exceptions);

                if ($this->eventManager->notifyUntil('Shopware_Components_Error_Log', [
                    'exception' => $last,
                ]))
public function testEvent(): void
    {
        $activateContext = $this->createMock(ActivateContext::class);
        $exception = new \Exception('failed');
        $event = new PluginPostDeactivationFailedEvent(
            new PluginEntity(),
            $activateContext,
            $exception
        );
        static::assertInstanceOf(PluginLifecycleEvent::class$event);
        static::assertEquals($activateContext$event->getContext());
        static::assertEquals($exception$event->getException());
    }
}
'Enlight_Controller_Front_PostDispatch' => ['onDispatchEvent', 100],
            'Enlight_Controller_Front_DispatchLoopShutdown' => ['onDispatchEvent', 100],
        ];
    }

    public function onDispatchEvent(EventArgs $args)
    {
        if (!$args->getResponse()->isException()) {
            return;
        }

        $exception = $args->getResponse()->getException();
        $this->handleException($exception[0]);
    }

    /** * @param Exception $exception * * @throws Exception */
    private function handleException($exception)
    {
        $request = new Enlight_Controller_Request_RequestHttp();
        
/** @var PathBuilder $pathBuilder */
        $pathBuilder = $this->container->get('path.builder');

        $debug = false;
        $step = new UnpackStep($localFilesytem$remoteFilesystem$pathBuilder$debug);

        $offset = 0;
        $total = 0;
        do {
            $result = $step->run($offset$total);
            if ($result instanceof ErrorResult) {
                throw new Exception($result->getMessage(), 0, $result->getException());
            }
            $offset = $result->getOffset();
            $total = $result->getTotal();
        } while ($result instanceof ValidResult);
    }

    private function updateHtaccess()
    {
        $this->container->get('shopware.update.update_htaccess')->update();
    }

    
Home | Imprint | This part of the site doesn't use cookies.