eZ Community » Forums » eZ Publish 5 Platform » Handling http errors in ez5
expandshrink

Handling http errors in ez5

Handling http errors in ez5

Monday 24 February 2014 3:11:56 pm - 19 replies

Is there anyway to handle http errors (like 404) in ez4 without using legacy mode? I read this http://share.ez.no/forums/ez-publish-5-platform/module-page-not-found-error but I don't like this way

Monday 24 February 2014 3:25:17 pm

Hi Aleksandar

http://symfony.com/doc/2.3/cookbook/controller/error_pages.html

Friday 21 March 2014 12:23:59 pm

Hi Jérôme

the problem is that an exception raised in the legacy controller (where all request for unsatisfied URLs are finally handled) does not seem to get forwarded to the TWIG controller handling the errors.

Is there a specific setting in error.ini which would cause TWIG error handling to be activated?

Thanks,
Donat

Monday 24 March 2014 9:37:19 am

Hi Donat

Do you mean when an exception is thrown from legacy ?

Monday 24 March 2014 10:32:18 am

Hi Jérôme

I was not very precise... No exception thrown, but with an invalid URL, LegacyKernelController::indexAction returns a 404 status code on the ez_legacy route (which is fine). Howerver, this is not forwarded to the TWIG controller handling the errors, but the standard TWIG pagelayout is invoked.

Unlike the behaviour of eZDemo I do not see the legacy kernel error message.

In my opinion error status codes returned from the legacy controller should be handled by the TWIG controller. I now have a really dirty "solution" which checks for ezpublish.legacy and includes a separate error template - as we have no legacy code at all, we should never see ezpublish.legacy, but this is certainly no good solution...

Tuesday 08 April 2014 8:49:30 pm

Have you find a solution ?

Friday 11 April 2014 2:28:29 pm

I'm not very knowledgeable in this area, but from my hill, I'd agree with you, Donat.

What do you think, Jérôme ?

Edit: Jérôme is neck deep in a nasty feature, and will reply when he's able to breathe happy.gif Emoticon

Modified on Friday 11 April 2014 2:48:56 pm by Bertrand Dunogier

Friday 18 April 2014 7:00:31 pm

for me, if I have a 404, legacy controller catch the information :

 [2014-04-18 18:56:00] app.INFO: Router  eZ\Bundle\EzPublishCoreBundle\Routing\UrlAliasRouter was not able to  match, message "Could not find 'UrlAlias' with identifier 'tttt'" [] []
[2014-04-18  18:56:00] request.INFO: Matched route "ez_legacy" (parameters:  "_route": "ez_legacy", "_controller":  "ezpublish_legacy.controller:indexAction") [] []

Friday 06 June 2014 8:06:21 pm

Hi,

I realize that I'm a bit late in the game here, but I hit this same issue and solved it by placing an intermediate router between the symfony and legacy routers in the the chain router. This allows me to intercept all requests to the legacy router and determine if it should continue or do something else.

Monday 09 June 2014 3:49:45 pm

Hi Michael !

Have you an exemple ? I have 2 website in my ez5 instance and i need to have a custom 404 error for the 2 website.

Thanks

Djoo

Monday 09 June 2014 5:03:23 pm

Here is an example gist of the files which are being used: https://gist.github.com/quantumlord42/3a010e85983bae634dc6

The final controller being used for the error handling is hard coded, but this was my first go working with routers. This solution does not work for a 403 Forbidden error since the request does get a match by the initial router in the chain. 

Wednesday 11 June 2014 4:03:30 pm

Awesome happy.gif Emoticon

I have a beautiful 404 page happy.gif Emoticon

Thanks Michael

Friday 20 June 2014 11:21:46 am

Hi,

First of all - thanks Michael, for your nice solution. I have a beautiful 404 page as well now happy.gif Emoticon
One thing though; after implementing your solution, the HTTP code that I get back is 200, instead of the expected 404. Any idea why this might happen? Google will not be happy if we output a 200 where a 404 is expected

Friday 20 June 2014 3:40:52 pm

Hi,

glad to be able to help. In the custom error controller on the response object you would set the status code similar to:

$Response = new Response();
$Response->setStatusCode(404);
return $Response;

Remember that the returned value of a render in the controller is a Response object.

Modified on Friday 20 June 2014 3:42:22 pm by Michael O'Connor

Friday 20 June 2014 4:57:12 pm

Thanks! Works perfectly now happy.gif Emoticon

Sunday 27 July 2014 2:01:59 pm

Hi Michael, I got an error implementing your solution

If I dump my routes with:

 php ezpublish/console router:debug

I got this error:

ContextErrorException: Catchable Fatal Error: Argument 1 passed to Symfony\Component\Routing\RouteCollection::addCollection() must be an instance of Symfony\Component\Routing\RouteCollection, null given, called in /var/www/html/vendor/symfony-cmf/routing/Symfony/Cmf/Component/Routing/ChainRouter.php on line 301 and defined in /var/www/html/vendor/symfony/symfony/src/Symfony/Component/Routing/RouteCollection.php line 128

Unfortunately I'm not an expert in chaining routing... If you have some hints will be really appreciated happy.gif Emoticon

Gabriele

Modified on Monday 28 July 2014 10:31:13 pm by Gabriele Perego

Monday 28 July 2014 6:48:34 pm

Hi Gabriele,

I did a little digging and was able to reproduce the error you found. Since I was not really concerned with the console commands at the time, and I did everything in the matchRequest method, I had not run into this yet.

The cause of the issue is in the getRouteCollection method of the class. This method seems to be what gets called by the console command. As you can see in the example code I provided, I left that method returning null. If you set that method to return new instance of "\Symfony\Component\Routing\RouteCollection", the error will be resolved. I would guess that this method could (maybe even should) be called by the matchRequest method anyway.

Hope that helps,

Michael

Monday 28 July 2014 10:31:58 pm

Ciao Michael, issue fixed. thanks a lot

Gabriele

Monday 24 November 2014 10:35:31 am

Hi,

I have a problem with the code. I don't understand why, but in the siteRouter.php (when i call the legacy function "/content/download" this code make problem :

  $eZPublishLegacyKernel = call_user_func(                    
        $this->Container->get('ezpublish_legacy.kernel')
 );

I have this error on the get legacy kernel :

The security context contains no authentication token. One possible reason may be that there is no firewall configured for this URL

Monday 01 December 2014 10:14:37 am

Hello Johann,

I have the same problem as you.
Have you found a solution?

Thank you in advance.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from