summaryrefslogtreecommitdiffstats
path: root/application/controllers/Api.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2020-04-19 13:47:34 +0200
committerFlorian Pritz <bluewind@xinu.at>2020-04-19 13:55:45 +0200
commitac934ca94370f5204319f88eef0a7747fe7e133a (patch)
treeaadc36591663cb706f4b208491b3ceed5e6abc55 /application/controllers/Api.php
parentddf6734dfeac65babf096a3147338f54d712b6e3 (diff)
Reclassify various exceptions as UserInputException
These are errors that a user can correct themselves so we should classify them accordingly. That way they get the correct HTTP status code and they also get ignored by the logging code. Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/controllers/Api.php')
-rw-r--r--application/controllers/Api.php12
1 files changed, 6 insertions, 6 deletions
diff --git a/application/controllers/Api.php b/application/controllers/Api.php
index 1fa49cb46..4f32ad427 100644
--- a/application/controllers/Api.php
+++ b/application/controllers/Api.php
@@ -24,7 +24,7 @@ class Api extends MY_Controller {
$function = $this->uri->segment(4);
if (!preg_match("/^v([0-9]+)(.[0-9]+){0,2}$/", $requested_version)) {
- throw new \exceptions\PublicApiException("api/invalid-version", "Invalid API version requested");
+ throw new \exceptions\UserInputException("api/invalid-version", "Invalid API version requested");
}
$requested_version = substr($requested_version, 1);
@@ -32,11 +32,11 @@ class Api extends MY_Controller {
$major = intval(explode(".", $requested_version)[0]);
if (!preg_match("/^[a-zA-Z-_]+$/", $controller)) {
- throw new \exceptions\PublicApiException("api/invalid-endpoint", "Invalid endpoint requested");
+ throw new \exceptions\UserInputException("api/invalid-endpoint", "Invalid endpoint requested");
}
if (!preg_match("/^[a-zA-Z-_]+$/", $function)) {
- throw new \exceptions\PublicApiException("api/invalid-endpoint", "Invalid endpoint requested");
+ throw new \exceptions\UserInputException("api/invalid-endpoint", "Invalid endpoint requested");
}
$namespace = "controllers\\api\\v".$major;
@@ -44,16 +44,16 @@ class Api extends MY_Controller {
$class_info = $namespace."\\api_info";
if (!class_exists($class_info) || version_compare($class_info::get_version(), $requested_version, "<")) {
- throw new \exceptions\PublicApiException("api/version-not-supported", "Requested API version is not supported");
+ throw new \exceptions\UserInputException("api/version-not-supported", "Requested API version is not supported");
}
if (!class_exists($class)) {
- throw new \exceptions\PublicApiException("api/unknown-endpoint", "Unknown endpoint requested");
+ throw new \exceptions\UserInputException("api/unknown-endpoint", "Unknown endpoint requested");
}
$c= new $class;
if (!method_exists($c, $function)) {
- throw new \exceptions\PublicApiException("api/unknown-endpoint", "Unknown endpoint requested");
+ throw new \exceptions\UserInputException("api/unknown-endpoint", "Unknown endpoint requested");
}
return $this->send_json_reply($c->$function());
} catch (\exceptions\PublicApiException $e) {