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

ahmeda's avatar

Exception\NotFoundHttpException error ?

I just deployed my Laravel app on AWS and link SSL Certificate and all things are good with everything!

In my app, I just link my logs app via a slack channel to send any error logs to it!

The weird thing when I visit any URL on the website I got this error in the slack channel:

Symfony\Component\HttpKernel\Exception\NotFoundHttpException in 
/var/app/current/vendor/laravel/framework/src/Illuminate/Routing/AbstractRouteCollection.php:43

Stack trace:
#0 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php(162):
Illuminate\Routing\AbstractRouteCollection->handleMatchedRoute(Object(Illuminate\Http\Request), NULL)

Some info:

I'm using AWS EB Linux 2, PHP 7.4 running on 64bit Amazon Linux 2/3.1.2 ) of course Nginx!

And I deploy my app via code commit and Pipeline to EB directly.

What I did from my search on google:

  • I thought it's because of some / in Route and check all my route and remove the /! but still, I got the same error!

  • I thought it's because of SSL some route still sending HTTP not HTTPS, so I just create a file in this path to just convert every HTTP request to https one.

.platform/niginx/conf.d/elasticbeanstalk/https.conf

# HTTP to HTTPS

if ($http_x_forwarded_proto = 'http') {
  return 301 https://$host$request_uri;
}

Also Still got the same error!

  • The last one I read it's maybe because of some file in the network get 404! and I just check the network section and get just one file which favicon.ico, fixes this but still getting the same error :(

What else guys ?! :(

0 likes
23 replies
s4muel's avatar

is that the whole stack trace? i am not sure about the NULL parameter in handleMatchedRoute(Object(Illuminate\Http\Request), NULL) does the app work fine, right? just that error occurs? with every request or randomly?

what does php artisan route:list say? any possible duplicated routes? or a controller redirecting to a route with different http method?

lacasera's avatar

@rabeea I suspect in your deploy pipleline, you are caching routes. try running the commands below somewhere in your pipeline

php artisan cache:clear
php artisan route:cache
1 like
ahmeda's avatar

@s4muel @lacasera

Here is the full error:

Symfony\Component\HttpKernel\Exception\NotFoundHttpException in /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/AbstractRouteCollection.php:43
Stack trace:
#0 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php(162): Illuminate\Routing\AbstractRouteCollection->handleMatchedRoute(Object(Illuminate\Http\Request), NULL)
#1 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Router.php(639): Illuminate\Routing\RouteCollection->match(Object(Illuminate\Http\Request))
#2 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Router.php(628): Illuminate\Routing\Router->findRoute(Object(Illuminate\Http\Request))
#3 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Router.php(617): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#4 /var/app/current/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(165): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#5 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#6 /var/app/current/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(60): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#7 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Barryvdh\Debugbar\Middleware\InjectDebugbar->handle(Object(Illuminate\Http\Request), Object(Closure))
#8 /var/app/current/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#9 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#10 /var/app/current/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#11 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#12 /var/app/current/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#13 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(Object(Illuminate\Http\Request), Object(Closure))
#14 /var/app/current/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(63): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#15 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#16 /var/app/current/vendor/fruitcake/laravel-cors/src/HandleCors.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#17 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fruitcake\Cors\HandleCors->handle(Object(Illuminate\Http\Request), Object(Closure))
#18 /var/app/current/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#19 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fideloper\Proxy\TrustProxies->handle(Object(Illuminate\Http\Request), Object(Closure))
#20 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#21 /var/app/current/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(140): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#22 /var/app/current/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(109): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#23 /var/app/current/public/index.php(55): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#24 {main}
jmpalacios's avatar

Hi @jean_ali , did you ever find a solution to this problem? I'm running into the exact same issue, NotFoundHttpException thrown in vendor/laravel/framework/src/Illuminate/Routing/AbstractRouteCollection.php:43, with a Illuminate\Routing\AbstractRouteCollection->handleMatchedRoute(Object(Illuminate\Http\Request), NULL) call leading right up to it in the stack trace.

Other than that, as far as I can see my application is running just fine. My extensive test suite is fully passing, 'php artisan route:list' is not showing any duplicate routes, at least as far as I can see, all routes shown there work as expected, and I don't think I have any redirects to other routes with different HTTP methods.

Thanks in advance for any help!

1 like
ahmeda's avatar

@jmpalacios Unfortunately I did not find any solution for this issue still facing it!

jmpalacios's avatar

@Jean_ali Thanks for the confirmation! I'll keep searching and post here whatever solution I find.

Snapey's avatar

@jmpalacios You should not need to log 404 errors. These will happen all the time, from malicious probes, web crawlers and even your browser trying to load source maps for compiled assets.

ahmeda's avatar

@Snapey So what is the code that I make 404 error not sent to log!?

jmpalacios's avatar

@Jean_ali @snapey I think I figured it out!

I'm aware that 404 errors will happen all the time, and I'm also aware 4xx HTTP errors shouldn't be reported in the error log, and what's confusing me precisely is the fact they're being reported, which in my case only just started happening rather recently for my application.

And where I think the mystery lies is in the exception handler's reporting facilities. Recently, for a number of reasons, I decided to log token mismatch errors for a specific route in my application, for which I overrode Illuminate\Foundation\Exceptions\Handler's $internalDontReport array in App\Exceptions\Handler, to remove Illuminate\Session\TokenMismatchException from it while keeping its other entries, which as of Laravel 8.x includes Symfony\Component\HttpKernel\Exception\HttpException, parent to Symfony\Component\HttpKernel\Exception\NotFoundHttpException.

But what's most probably going on in my case is that in App\Exceptions\Handler I failed to import the symbols for those other exceptions in $internalDontReport, so now the symbol name HttpException::class is resolving to App\Exceptions\HttpException, rather than the intended Symfony\Component\HttpKernel\Exception\HttpException, and hence failing the $e instanceof $type test in Illuminate\Foundation\Exceptions->shouldntReport().

If that's correct, which I'm about to test, my application should continue producing 404 errors, of course, but it should no longer report them. I'll inform here once I gather data for that.

1 like
jmpalacios's avatar

Indeed, my presumption was right! I wrote a test (which I can share if anyone likes) that failed right away, and turned to green just upon importing the correct symbols in App\Exceptions\Handler.

So, with this deployed to my application, HTTP 4xx errors will hopefully no longer be reported.

1 like
jmpalacios's avatar

@Jean_ali If you mean the test, here you go:

<?php

declare(strict_types=1);

namespace App\Exceptions;

(…)

class Handler extends ExceptionHandler
{

(…)

    /**
     * A list of the internal exception types that should not be reported.
     * Overridden to remove TokenMismatchException.
     *
     * @var string[]
     */
    protected $internalDontReport = [
        AuthenticationException::class,
        AuthorizationException::class,
        HttpException::class,
        HttpResponseException::class,
        ModelNotFoundException::class,
        MultipleRecordsFoundException::class,
        RecordsNotFoundException::class,
        SuspiciousOperationException::class,
        ValidationException::class,
    ];

    /**
     * Determine if the exception should be reported.
     * Overridden solely to change the method's visibility.
     */
    public function shouldntReport(Throwable $e): bool
    {
        return parent::shouldntReport($e);
    }
}
<?php

declare(strict_types=1);

namespace Tests\Unit;

use App\Exceptions\Handler;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Contracts\Container\Container;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Database\MultipleRecordsFoundException;
use Illuminate\Database\RecordsNotFoundException;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Session\TokenMismatchException;
use Illuminate\Validation\ValidationException;
use stdClass;
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpFoundation\Response;
use Tests\TestCase;
use Throwable;

class ExceptionHandlerTest extends TestCase
{
    protected array $internalDontReport = [
        AuthenticationException::class,
        AuthorizationException::class,
        HttpException::class,
        HttpResponseException::class,
        ModelNotFoundException::class,
        MultipleRecordsFoundException::class,
        RecordsNotFoundException::class,
        SuspiciousOperationException::class,
        ValidationException::class,
    ];

    protected array $shouldReport = [
        TokenMismatchException::class,
    ];

    protected Handler $handler;

    protected function setUp(): void
    {
        parent::setUp();
        $this->handler = new Handler($this->createMock(Container::class));
    }

    protected function newThrowable(string $type): Throwable
    {
        switch ($type) {
            case HttpException::class:
                $e = new $type(500);
                break;

            case HttpResponseException::class:
                $e = new $type(new Response());
                break;

            case ValidationException::class:
                $e = new $type(new stdClass());
                break;

            default:
                $e = new $type();
        }

        return $e;
    }

    /**
     * @test
     */
    public function selectExceptionsShouldNotBeReported(): void
    {
        collect($this->internalDontReport)->each(function (string $type, int $key): void {
            $this->assertTrue($this->handler->shouldntReport($this->newThrowable($type)));
        });
    }

    /**
     * @test
     */
    public function selectExceptionsShouldBeReported(): void
    {
        collect($this->shouldReport)->each(function (string $type, int $key): void {
            $this->assertTrue($this->handler->shouldReport($this->newThrowable($type)));
        });
    }
}

That test fails if you don't import the exception symbols in App\Exceptions\Handler, but as soon as you do it goes right back to green and, at least in my case, HTTP 4xx exceptions stopped being reported in the error log.

1 like
ahmeda's avatar

@jmpalacios Can I put your exceptions in dontReport? & what is different with your way?

protected $dontReport = [
        //your exceptions 
    ];
jmpalacios's avatar

@Jean_ali Thing is, in the case of Illuminate\Session\TokenMismatchException, I did want to report it (not always, just under very specific circumstances), so registering a handler for it with Illuminate\Foundation\Exceptions->reportable() was not sufficient because it's by default in $internalDontReport[], and Illuminate\Foundation\Exceptions->report() always checks that first through Illuminate\Foundation\Exceptions->shouldntReport(), so the only workaround I found was to override the $internalDontReport array to remove TokenMismatchException.

But if there's a better way, please, I'm all ears!

Snapey's avatar

by default it doesn't. If you are seeing these in the Laravel log then you must have changed something in the error handler.

If you are talking about the web server log, then this is normal.

ahmeda's avatar

@Snapey I link with slack like this:

in  App\Exceptions\Handler

public function report(Throwable $exception)
    {
        Log::channel('slack')->error($exception);
    }
ahmeda's avatar

@Snapey


class Handler extends ExceptionHandler
{
 
    protected $dontReport = [
        //
    ];

    protected $dontFlash = [
        'password',
        'password_confirmation',
    ];

    public function report(Throwable $exception)
    {
        Log::channel('slack')->error($exception);
    }
}
Snapey's avatar

@Jean_ali add into the don't report array

    \Symfony\Component\HttpKernel\Exception\HttpException::class,

However, I note in the error handler docs;

Behind the scenes, Laravel already ignores some types of errors for you, such as exceptions resulting from 404 HTTP "not found" errors or 419 HTTP responses generated by invalid CSRF tokens.

So, it sounds like this is broken in some way.

1 like
YassineEl204's avatar

please help me this problem laravel how to

1 C:\wamp64\www\pay\vendor\laravel\framework\src\Illuminate\Routing\AbstractRouteCollection.php:179 Illuminate\Routing\AbstractRouteCollection::addToSymfonyRoutesCollection(Object(Symfony\Component\Routing\RouteCollection), Object(Illuminate\Routing\Route))

2 C:\wamp64\www\pay\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php:246 Illuminate\Routing\AbstractRouteCollection::toSymfonyRouteCollection()

CamKem's avatar

@YassineEl204 Please do not reply to old & solved threads. If you have a question create a new forum post & detail your issue, so we can help you. By responding to an old thread like this, no one will help you.

jasonpol24's avatar

please help me this problem laravel how to exception : "Symfony\Component\HttpKernel\Exception\NotFoundHttpException" file : "C:\Sites\agenda\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php" line : 179 message : ""

Please or to participate in this conversation.