Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bypass Laravel Exception handling

I have a method that checks if a user has valid Session info. This is supposed to throw an Exception, Guzzle\Http\Exception\BadResponseException but when I try to catch it :

catch (Guzzle\Http\Exception\BadResponseException $e) 
{
    return false;
} 
return true

Laravel doesn't get to this code and immediately starts it's own error handling. And ideas on how to bypass Laravels own implementation and use my own Catch.

EDIT: I just found out Laravel uses the same Exception handler as Symfony, so I also added the Symfony2 tag.

EDIT 2:

I sort of fixed the issue by disabling Guzzle exceptions and checking the return header manually. It's a bit of a short cut but in this case, it does the job. Thanks for the responses!

like image 423
Martijn Avatar asked Oct 14 '13 12:10

Martijn


People also ask

How do I get exception error in Laravel?

In Laravel 5 you can catch exceptions by editing the render method in app/Exceptions/Handler. php . This will be applied to ANY exception in AJAX requests. If your app is sending out an exception of App\Exceptions\MyOwnException , you check for that instance instead.

What is http exception in Laravel?

First of all, if you have an HTTP exception, meaning an exception that only makes sense in the context of an HTTP request/response cycle, then you should be able to throw it where it occurs and not throw something else with the purpose of converting it when it reaches the controller, this is what the abort helpers are ...


1 Answers

Actually this exception can be catched in Laravel, you just have to respect (and understand) namespacing:

If you have

namespace App;

and you do

catch (Guzzle\Http\Exception\BadResponseException $e) 

PHP understands that you are trying to

catch (\App\Guzzle\Http\Exception\BadResponseException $e) 

So, for it to work you just need a root slash:

catch (\Guzzle\Http\Exception\BadResponseException $e) 

And it will work.

like image 144
Antonio Carlos Ribeiro Avatar answered Sep 25 '22 15:09

Antonio Carlos Ribeiro