2

I am using the Stripe API and Laravel together. If Stripe detects an error charging the card (such as using a test credit card number that throws an invalid security code error), the API bindings are supposed to throw an exception, which they do. The problem is, I am having issues catching the exception before Laravel throws up the error 500 page (I am trying to perform a redirect with an error message instead).

The code I've written is available on Pastebin: http://pastebin.com/ZaW2xbbt

The behavior I'm expecting is for the catch to fire and the redirect to be performed, but instead, I get the stack trace with the message and "Unhandled Exception". That's confusing me because I am handling the exception.

Variables such as $customer are valid and have been defined previously. Any ideas what's going on?

5
  • To catch laravel exception, use \Exception Commented Mar 29, 2013 at 4:21
  • That still seems to show the default stack trace, regardless what namespace I prefix Extension with (root or otherwise) Commented Mar 31, 2013 at 17:02
  • So you're importing those exceptions into the current namespace scope then? Commented Apr 6, 2013 at 9:22
  • That pastebin doesn't appear to be valid. Are you using Laravel 3 or Laravel 4? Commented Jun 14, 2013 at 11:54
  • The Pastebin was set to expire, though the issue was in a Laravel 4 application. I did solve the problem, and I'll have to go back and find the solution and post it here. Commented Jun 14, 2013 at 18:27

2 Answers 2

6

For any future viewers, here's an article on error handling in laravel 4.

Laravel 4 lets you catch Exceptions by exception type. For instance, you can handle Symfony's HttpException and of its sub-classes by adding this to your code:

// Catch HttpException, NotFoundHttpException, etc etc
App::error(function(HttpException $exception, $code, $fromConsole)
{
    ...
});

Symfony HttpExceptions (used in Laravel) can be found here.

You can also throw this in a ServiceProvider:

<?php namespace My\Namespace;

use Illuminate\Support\ServiceProvider;
use Symfony\Component\HttpKernel\Exception\HttpException;

class MyServiceProvider extends ServiceProvider {

    public function register()
    {
            $this->app->error(function(HttpException $exception, $code, $fromConsole)
            {
                ...
            });
    }

}

Hope that helps!

Sign up to request clarification or add additional context in comments.

Comments

0

Generally, all errors logged by Laravel are logged under storage/logs folder

Anyway, the 500 error could be a syntax/parse error, in such case the Laravel framework could be not yet loaded when the error occurs and if so, the exception is not lhandled by Laravel.

In this case you should access the apache/vargrant/whatif php error log in some way (dependently on your server capabilities and configuration), in my personal cases I have configured the server to put that logs in a /storage/logs/error_log.txt file such that I can access them as other Laravel server logs

Note that in Laravel 5, you have app/Exceptions/Handler.php as entry point for customize exception handling/reporting

https://laravel.com/docs/5.7/errors#the-exception-handler

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.