diff --git a/Source/API/script/ExceptionHandle/HttpNotFoundError.php b/Source/API/script/ExceptionHandle/HttpNotFoundError.php index 41cde83..472c2ee 100644 --- a/Source/API/script/ExceptionHandle/HttpNotFoundError.php +++ b/Source/API/script/ExceptionHandle/HttpNotFoundError.php @@ -9,7 +9,7 @@ use Throwable; class HttpNotFoundError extends HttpSpecializedException { protected $code = 404; - protected $message = "Wrong URL, verify the right call of the API. Exemple :'http://url?method=getSomething&id=5'"; + protected $message = "Method not found on the API, verify the method's name."; public function __construct(ServerRequestInterface $request,?Throwable $previous = null) { diff --git a/Source/API/script/index.php b/Source/API/script/index.php index 7286c8c..0ec8d0c 100644 --- a/Source/API/script/index.php +++ b/Source/API/script/index.php @@ -1,5 +1,6 @@ addRoutingMiddleware(); * @param bool $logErrors -> Parameter is passed to the default ErrorHandler * @param bool $logErrorDetails -> Display error details in error log */ -$errorMiddleware = $app->addErrorMiddleware(true, true, true); +$errorMiddleware = $app->addErrorMiddleware(true, true, false); /** * Add a route for the API @@ -37,11 +38,16 @@ $app->get('/', function (Request $request, Response $response) { } unset($parameters['method']); $listGateway = array("\\Gateway\\GatewayForm", "\\Gateway\\GatewayKeyword", "\\Gateway\\GatewayQuestion"); + $ok = false; foreach ($listGateway as $gateway){ if (method_exists($gateway, $method)) { + $ok = true; $response->getBody()->write(json_encode((new $gateway)->$method($parameters))); } } + if (!$ok){ + throw new HttpNotFoundError($request); + } $temp = array(0 => array("id" => "1", "0" => "1", "title" => "Votre avis nous intéresse !",