Shironekomaru
Shironekomaru

Reputation: 481

Method 'App\Exceptions\Handler::render()' is not compatible with method 'Illuminate\Foundation\Exceptions\Handler::render()'.intelephense(1038)

Why do I have this intelephense error of incompatibility between two methods? Did I put two different overlapping methods? What should I fix in the code. I'm watching a laravel 5.6 tutorial as a reference so maybe some syntax is now incompatible and I can't seem to find the right fix on this. I am using laravel 8.x. Thank you.

here is my handler.php code:


namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
use Tymon\JWTAuth\Exceptions\JWTException;

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 = [
        'current_password',
        'password',
        'password_confirmation',
    ];

    /**
     * Register the exception handling callbacks for the application.
     *
     * @return void
     */
    public function register()
    {
        $this->reportable(function (Throwable $e) {
            //
        });
    }

    public function render($request, Exception $exception)
    {
        if($exception instanceOf JWTException){
            return response(['error' => 'Token is not provided'], 500);
        }
        return parent::render($request, $exception);
    }
}

VS Code Error

Upvotes: 1

Views: 5744

Answers (3)

Daniel Katz
Daniel Katz

Reputation: 2408

I just forgot to add use Throwable;

Upvotes: 1

Govar
Govar

Reputation: 124

try this

    public function render($request, Throwable $exception)
    {
        if($exception instanceOf JWTException){
            return response(['error' => 'Token is not provided'], 500);
        }
        return parent::render($request, $exception);
    }

Upvotes: 0

Shironekomaru
Shironekomaru

Reputation: 481

For those who'll encounter this in using 5.6 as reference but is building in 8.x, The simple solution which I missed is using Exception instead of Throwable

Upvotes: 3

Related Questions