php - Ignore and continue on specific Symfony2 kernel.exception event -


Text after "itemprop =" text ">

Scenario:

The Symfony2 project works with the main database and a secondary (remote) remote data Does. The remote database may be down or the connection between them may be different. In this case I still want to continue execution as normal, although with notice that the remote is down.

I have tried this in my event listener:

  Kernel exceptions on public function (GetResponseForExceptionEvent $ event) {$ exception = $ event-> GetException (); If ($ instanceof instanceof PDOException || $ exceptions ConnectionException || $ exception instanceof \ PDOException || $ exceptions DBALException instanceuff exception) {$ this- & gt; Flash & gt; Flashmessage ('remote_server_connection_error', array (), FlashBagUtil :: TYPE_ALERT); // $ kernel = $ event- & gt; GetKernel (); // $ request = $ event- & gt; GetRequest (); // $ response = $ kernel- & gt; Handle ($ request, http: //reterface :: MASTER_REQUEST, is true); // $ response-> Set Status Code (Answer: HTTP_OK); // $ Event-> Set Response ($ response); $ Event & gt; StopPropagation (); The echo 'works'; }}  

If I reduce the part of the response, then I hope the page will be taken back, but the position is not 500, not 200, as I clearly set Have done The "work" becomes echoed and the incident part is working fine.

What is the correct way of ignoring this for working with an exception and for the comfort of the request from the Symfony2 kernel.exception listener?

Many thanks

As .exception for the kernel Event:

Symfony ensures that the response status is set to the one based on the most appropriate exception to the code, Set the position on the response will not work. If you want to overwrite the status code (which you should not have without a good reason), then set the X-State-code header

So you have to set this header :

$ response-> header-> Set ('x-status-code', response: HTTP_OK);

Comments