Server Error 500 when trying to implement Error Handler

Hello, I’m reaching out, some previous experience with Slim 3 moving to 4. I’m trying to implement the code given in the official documentation here: Application - Slim Framework

Stangely I have a 500 Error thrown when accessing the root of the website, (I did create a basic Hello World route for / that worked fine before I’ve set up the 2 given classes)

Looking at the psr7 version it is the 1.7
Here is the full error message
{ “statusCode”: 500, “error”: { “type”: “SERVER_ERROR”, “description”: “{closure}(): Argument #1 ($request) must be of type Request, Slim\\Psr7\\Request given, called in \/Users\/patrice\/Documents\/www\/www-idapremsel\/vendor\/slim\/slim\/Slim\/Handlers\/Strategies\/RequestResponse.php on line 39” } }

I must add that if I type /gibberishxxxx I get a 404 so something is working :wink:

Any ideas? Thanks!!!

If I am right the psr7 Request type is not the one given to your closure.

Try adding this

use Psr\Http\Message\ServerRequestInterface as Request;

Nice hint!!! I added your code and still the same… But the culprit was not the Request object but the response… So adding

use Psr\Http\Message\ResponseInterface as Response;

Solved the issue!!! Hello World!.. Thanks!! Is this bit missing from the official documentation example? Or my wrong doing copying pasting…

1 Like

Great news.

I am using slim/slim-skeleton as a base of my projects and composer. The base exemple showed me those 2 lines (Request and Response).

Habe fun

Great idea I will start from there.

All the best