特定のケースに基づいてストライプがスローする可能性があるすべての例外に対するStripe例外ラッパーがあります。私はその例外がスローされるイベントリスナーを登録しようとしていますが、リスナーが解雇されたようには見えません。例外リスナーを登録するsymfony3
jsonレスポンスでイベントを返す代わりに、例外が500をスローしてスタックトレースをレンダリングします。私が紛失しているものがありますか?
// AppBundle/Exceptions/StripePaymentException.php
namespace AppBundle\Exceptions;
use Exception;
class StripePaymentException extends Exception {
public $response;
public $message;
public function __construct($message, $response, $code = 0, Exception $previous = null)
{
parent::__construct($message, $code);
$this->message = $message;
$this->response = $response;
}
public function getResponse()
{
return $this->$response;
}
}
// AppBundle/EventListener/StripePaymentExceptionListener.php
namespace AppBundle\EventListener;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
class StripePaymentExceptionListener
{
public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
$data = $exception->getResponse();
$response = new JsonResponse($data);
$event->setResponse($response);
}
}
// services.yml
app.stripe_payment_exception_listener:
class: AppBundle\EventListener\StripePaymentExceptionListener
tags:
- { name: kernel.event_listener, event: kernel.exception, priority: 200 }
どのエラーが正確に行うかあなたは検索しますか? –
@AlessandroMinoccheri例外がスローされますが、(リスナーを介して)期待どおりの方法でフォーマットされません。それは単にレスポンスを返すのではなく、500ページを投げて新しいページをレンダリングしています。 – mashedpotatoes