In this episode, we walk through how to set up the Whoops error handling package with a Slim 4 application. We start by scaffolding a fresh Slim 4 project using the Slender package for a minimal setup. First, we look at what kind of error pages Slim shows out-of-the-box—which, honestly, aren't the friendliest or most helpful, especially during development.
Next, we add Slim’s own error middleware to see how it improves the error pages a bit. While that makes things better, it's still not as nice as what Whoops gives us. So, to level things up, we install the slim/whoops
package, which wraps Whoops for easy use with Slim.
We then set up the Whoops middleware in our app—just a simple app->add()
—and see the Whoops error page in action. To be responsible developers, we also show how to conditionally enable Whoops only in development (using an environment variable like APP_DEBUG
), so users never see friendly but potentially sensitive error info in production.
Finally, there’s a quick tip on configuration and a reminder that there are plenty more options in the documentation if you want to take things further. By the end of the episode, you'll have a much nicer error page whenever something breaks in Slim—and the know-how to keep it safe in production environments!