Use the new custom error when method not found
continuous-integration/drone/push Build is passing Details

master
dorian.hodin 2 years ago
parent 233efb7dba
commit 3f918b2949

@ -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)
{

@ -1,5 +1,6 @@
<?php
use ExceptionHandle\HttpNotFoundError;
use ExceptionHandle\TypeErrorMethod;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
@ -23,7 +24,7 @@ $app->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 !",

Loading…
Cancel
Save