Commit 3eb5065c authored by thiaramus's avatar thiaramus
Browse files

Throw HTTP response code 400 on wrong API calls at bootstrap level

parent a156461e
......@@ -33,13 +33,20 @@
$apiClassName = 'api' . ucfirst($apiCallPath[0]);
// Autoload a matching class or return an error message if there is no such class
if (class_exists($apiClassName)) {
$apiClass = new $apiClassName($parsedUri);
if (is_a($apiClass, 'mainApiParent')) {
$apiClass->run();
try {
if (class_exists($apiClassName)) {
$apiClass = new $apiClassName($parsedUri);
if (is_a($apiClass, 'mainApiParent')) {
$apiClass->run();
} else {
throw new Exception('Invalid API endpoint');
}
} else {
echo "Invalid API method";
throw new Exception('Unknown API endpoint');
}
} else {
echo "Invalid API call";
}
\ No newline at end of file
} catch (Exception $e) {
http_response_code(400);
echo $e->getMessage();
}
Markdown is supported
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