Add Error Catch in the right section, and make response is not Json Type
continuous-integration/drone/push Build is passing Details

master
dorian.hodin 2 years ago
parent a2d3a146fa
commit 99b77cf7d1

@ -24,30 +24,31 @@ try{
* @param bool $logErrorDetails -> Display error details in error log * @param bool $logErrorDetails -> Display error details in error log
*/ */
$errorMiddleware = $app->addErrorMiddleware(true, true, true); $errorMiddleware = $app->addErrorMiddleware(true, true, true);
try {
$app->get('/', function (Request $request, Response $response) { $app->get('/', function (Request $request, Response $response) {
$parameters = $request->getQueryParams(); $parameters = $request->getQueryParams();
$method = $parameters['method']; $method = $parameters['method'];
$response->getBody()->write($method); $response->getBody()->write($method);
$listGateway = array("\\Gateway\\GatewayForm", "\\Gateway\\GatewayKeyword", "\\Gateway\\GatewayQuestion"); $listGateway = array("\\Gateway\\GatewayForm", "\\Gateway\\GatewayKeyword", "\\Gateway\\GatewayQuestion");
foreach ($listGateway as $gateway) // Pour chaque Gateway foreach ($listGateway as $gateway) // Pour chaque Gateway
{ {
if (method_exists($gateway, $method)) { if (method_exists($gateway, $method)) {
(new $gateway)->$method($parameters); // Si oui, on appelle cette fonction (new $gateway)->$method($parameters); // Si oui, on appelle cette fonction
}
}
$response->getBody()->write("Use the method $method, with the parameters ");
foreach ($parameters as $key => $value) {
$response->getBody()->write("Key =>" . $key . ", value =>" . $value);
} }
} return $response->withHeader('Content-type', 'application/json');
$response->getBody()->write("Use the method $method, with the parameters "); });
foreach ($parameters as $key => $value) { }catch (TypeError $t){
$response->getBody()->write("Key =>" . $key . ", value =>" . $value); echo "Error, wrong parameters key, or no parameters write : ".$t->getMessage();
} }
return $response;
});
// Run app // Run app
$app->run(); $app->run();
}catch (HttpNotFoundException $e){ }catch (HttpNotFoundException $e) {
echo "Error, not Found : ".$e->getMessage(); echo "Error, not Found : " . $e->getMessage();
}catch (TypeError $t){
echo "Error, wrong parameters key, or no parameters write : ".$t->getMessage();
} }

Loading…
Cancel
Save