Commit 2ed842b7 authored by Karamel's avatar Karamel
Browse files

Fix not logged and wrong api http responses.

parent e34d96bb
......@@ -29,7 +29,7 @@ $loginMiddleware = function($request, $response, $next) {
if ($userId === null && !$isLogin) {
// Reject the call because not authenticated.
$response = forbiddenResponse($response, 'Not logged');
$response = $response->withStatus(403, 'Not logged');
} else {
// Pass the call to the regular route
$response = $next($request, $response);
......
......@@ -45,16 +45,13 @@ $app = new \Slim\App([
$app->add(new \Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware($app));
include('../response_functions.php');
// Add login middleware
include('../middlewares/login_middleware.php');
$app->add($loginMiddleware);
// Default route
$app->get('/', function (Request $request, Response $response) {
return rejectedResponse($response, 'Wrong API');
return $response->withStatus(400, 'Wrong API');
});
// Other routes
......
<?php
/** Get an internal error response. */
function errorResponse($response, $reason) {
return $response->withStatus(500)->withJson($reason);
}
/** Get a forbidden error response. */
function forbiddenResponse($response, $reason) {
return $response->withStatus(403)->withJson($reason);
}
/** Get an user input error response. */
function rejectedResponse($response, $reason) {
return $response->withStatus(400)->withJson($reason);
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment