Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Rohrig's avatar

Stripe Error Handling in Handler Class

Can some tell me why I'm not hitting dd when I know that it is a stripe error being thrown?


namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Stripe\Error as Stripe;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that are not reported.
     *
     * @var array
     */
    protected $dontReport = [
        //
    ];

    /**
     * A list of the inputs that are never flashed for validation exceptions.
     *
     * @var array
     */
    protected $dontFlash = [
        'password',
        'password_confirmation',
    ];

    /**
     * Report or log an exception.
     *
     * @param  \Exception  $exception
     * @return void
     */
    public function report(Exception $exception)
    {
        parent::report($exception);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $exception
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $exception)
    {
        
        if ($exception instanceof \Stripe\Error\Card ||
            $exception instanceof \Stripe\Error\Api ||
            $exception instanceof \Stripe\Error\ApiConnection ||
            $exception instanceof \Stripe\Error\Authentication ||
            $exception instanceof \Stripe\Error\InvalidRequest ||
            $exception instanceof \Stripe\Error\Base)
        {

            dd('there was an error');

            
            $body = $exception->getJsonBody();
            $err  = $body['error']['message'];
            session()->flash('error_msg','There was a problem processing your request: ' . $err);
            return back();
        }
        return parent::render($request, $exception);
    }
}
0 likes
1 reply
Snapey's avatar

Why not dd ($exception) at the start of the functin?

Please or to participate in this conversation.