Hello, I’m migrating Slim2 to Slim 4 and I have a problem with my middleware before routing that load the correct version file of routes. The handle function return an error and I don’t understand why It tell me that it return a Slim\Http\Response instead of a Slim\Psr7\Response. In my uses, i precise that i use Slim\Psr7\Response. Any ideas ?
<h1>Slim Application Error</h1>
<div>
<p>The application could not run because of the following error:</p>
<h2>Details</h2>
<div><strong>Type:</strong> TypeError</div>
<div><strong>Code:</strong> 0</div>
<div><strong>Message:</strong> Closure::v1\{closure}(): Argument #2 ($response) must be of type
Slim\Psr7\Response, Slim\Http\Response given, called in
/var/www/html/myproject/vendor/sites/api/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php
on line 43</div>
<div><strong>File:</strong> /var/www/html/myproject/vendor/sites/api/app/controllers/v1/routes.php</div>
<div><strong>Line:</strong> 191</div>
<h2>Trace</h2>
<pre>#0 /var/www/html/myproject/vendor/sites/api/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(43): Closure->v1\{closure}()
#1 /var/www/html/myproject/vendor/sites/api/vendor/slim/slim/Slim/Routing/Route.php(384): Slim\Handlers\Strategies\RequestResponse->__invoke()
#2 /var/www/html/myproject/vendor/sites/api/vendor/slim/slim/Slim/MiddlewareDispatcher.php(81): Slim\Routing\Route->handle()
#3 /var/www/html/myproject/vendor/sites/api/vendor/slim/slim/Slim/MiddlewareDispatcher.php(81): Slim\MiddlewareDispatcher->handle()
#4 /var/www/html/myproject/vendor/sites/api/vendor/slim/slim/Slim/Routing/Route.php(341): Slim\MiddlewareDispatcher->handle()
#5 /var/www/html/myproject/vendor/sites/api/vendor/slim/slim/Slim/Routing/RouteRunner.php(84): Slim\Routing\Route->run()
#6 /var/www/html/myproject/vendor/sites/api/vendor/slim/slim/Slim/Middleware/BodyParsingMiddleware.php(68): Slim\Routing\RouteRunner->handle()
#7 /var/www/html/myproject/vendor/sites/api/vendor/slim/slim/Slim/MiddlewareDispatcher.php(147): Slim\Middleware\BodyParsingMiddleware->process()
#8 /var/www/html/myproject/vendor/sites/api/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php(59): Psr\Http\Server\RequestHandlerInterface@anonymous->handle()
#9 /var/www/html/myproject/vendor/sites/api/vendor/slim/slim/Slim/MiddlewareDispatcher.php(147): Slim\Middleware\RoutingMiddleware->process()
#10 /var/www/html/myproject/vendor/sites/api/public/index.php(74): Psr\Http\Server\RequestHandlerInterface@anonymous->handle()
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use Slim\Routing\RouteContext;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
use Slim\Exception\HttpNotFoundException;
use Slim\Psr7\Response;
use Selective\BasePath\BasePathMiddleware;
use Selective\BasePath\BasePathDetector;
Oh, now I see that you use use Slim\Psr7\Response; but your action handler returns a Slim\Http\Response object. Try to replace use Slim\Psr7\Response; with the generic interface:
use Psr\Http\Message\ResponseInterface as Response;