app\middleware\JWTAuth::process(): Return value must be of type support\Response, Webman\Http\Response returned
已指明返回類型,仍是報錯
app\\middleware\\JWTAuth::process(): Return value must be of type support\\Response, Webman\\Http\\Response returned
中間件
中間件正確使用方式
declare(strict_types=1);
namespace app\middleware;
use Tinywan\ExceptionHandler\Exception\ForbiddenHttpException;
use Tinywan\Jwt\JwtToken;
use Webman\Http\Request;
use Webman\Http\Response;
use Webman\MiddlewareInterface;
class AuthorizationMiddleware implements MiddlewareInterface
{
/**
* @param Request $request
* @param callable $handler
* @return Response
* @throws ForbiddenHttpException
*/
public function process(Request $request, callable $handler): Response
{
$request->userId = JwtToken::getCurrentId();
if (0 === $request->userId) {
throw new ForbiddenHttpException();
}
return $handler($request);
}
}