# Error handler no longer handles errors in Slim 4.15

**URL:** <https://discourse.slimframework.com/t/error-handler-no-longer-handles-errors-in-slim-4-15/6171>\
**Category:** Questions\
**Created:** [September 8, 2025, 8:54am UTC](https://discourse.slimframework.com/t/error-handler-no-longer-handles-errors-in-slim-4-15/6171 "2025-09-08T08:54:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kAlvaro](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/kalvaro/32/730_2.png) [@kAlvaro](https://discourse.slimframework.com/u/kAlvaro)\
**Post date:** [September 8, 2025, 8:54am UTC](https://discourse.slimframework.com/t/error-handler-no-longer-handles-errors-in-slim-4-15/6171/1 "2025-09-08T08:54:50Z")

</div>

Upgrading from 4.14.0 to 4.15.0 breaks custom error handlers for me. I configured error handler 2 or 3 years ago to have proper status codes and custom HTML pages for common HTTP errors. In 4.15, unknown URLs trigger 500 Internal Server Error and, in dev environment, show a stack trace.

```auto
<br />
<b>Fatal error</b>: Uncaught Slim\Exception\HttpNotFoundException: Not found. in C:\REDACTED\example.com\vendor\slim\slim\Slim\Middleware\RoutingMiddleware.php:76
Stack trace:
#0 C:\REDACTED\example.com\vendor\slim\slim\Slim\Middleware\RoutingMiddleware.php(44): Slim\Middleware\RoutingMiddleware-&gt;performRouting(Object(Slim\Psr7\Request))
#1 C:\REDACTED\example.com\vendor\slim\slim\Slim\MiddlewareDispatcher.php(129): Slim\Middleware\RoutingMiddleware-&gt;process(Object(Slim\Psr7\Request), Object(Psr\Http\Server\RequestHandlerInterface@anonymous))
#2 C:\REDACTED\example.com\vendor\slim\slim\Slim\MiddlewareDispatcher.php(73): Psr\Http\Server\RequestHandlerInterface@anonymous-&gt;handle(Object(Slim\Psr7\Request))
#3 C:\REDACTED\example.com\vendor\slim\slim\Slim\App.php(209): Slim\MiddlewareDispatcher-&gt;handle(Object(Slim\Psr7\Request))
#4 C:\REDACTED\example.com\vendor\slim\slim\Slim\App.php(193): Slim\App-&gt;handle(Object(Slim\Psr7\Request))
#5 C:\REDACTED\example.com\public\index.php(53): Slim\App-&gt;run()
#6 {main}
  thrown in <b>C:\REDACTED\example.com\vendor\slim\slim\Slim\Middleware\RoutingMiddleware.php</b> on line <b>76</b><br />

```

Step debugging shows that error handler is populated correctly (`\Slim\Middleware\ErrorMiddleware::$handlers`) but handler is never called.

I _may_ have done something wrong when I first configured it, because this part of the framework is not really something I fully understand.

1. I’ve created a custom class to set up middleware which I invoke in `index.php`:

2. My class calls a private method to configure some error handlers:

Am I doing something wrong, or it’s a legit bug?

---

<div class="post-metadata">

**Author:** ![akrabat](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/akrabat/32/9_2.png) [@akrabat](https://discourse.slimframework.com/u/akrabat)\
**Post date:** [September 8, 2025, 9:01am UTC](https://discourse.slimframework.com/t/error-handler-no-longer-handles-errors-in-slim-4-15/6171/2 "2025-09-08T09:01:17Z")

</div>

Would you mind raising an issue here [GitHub · Where software is built](https://github.com/slimphp/Slim/issues)?  
Ideally, with a minimal reproducible case in a single `index.php` file.

---

<div class="post-metadata">

**Author:** ![kAlvaro](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/kalvaro/32/730_2.png) [@kAlvaro](https://discourse.slimframework.com/u/kAlvaro)\
**Post date:** [September 9, 2025, 6:03pm UTC](https://discourse.slimframework.com/t/error-handler-no-longer-handles-errors-in-slim-4-15/6171/3 "2025-09-09T18:03:11Z")

</div>

It doesn’t happen when I do something similar in an empty project, perhaps it’s a clash with some other package. I need to investigate.

---

<div class="post-metadata">

**Author:** ![kAlvaro](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/kalvaro/32/730_2.png) [@kAlvaro](https://discourse.slimframework.com/u/kAlvaro)\
**Post date:** [September 9, 2025, 6:19pm UTC](https://discourse.slimframework.com/t/error-handler-no-longer-handles-errors-in-slim-4-15/6171/4 "2025-09-09T18:19:36Z")

</div>

I found the problem. I upgraded dependencies and added a fix to handle trailing slashes on the same day. While trying to figure out why my fix didn’t work, I moved the line of code to add routing middleware to the bottom. As the comment in the error middleware section warns:

> This middleware should be added last. It will not handle any exceptions/errors for middleware added after it.

Slim upgrade was a red herring. When I reverted to an earlier version, I also reverted my wrong move in middleware configuration.

Sorry!
