summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/controllers/api.php10
-rw-r--r--application/controllers/api/v1/file.php2
-rw-r--r--application/helpers/filebin_helper.php5
3 files changed, 9 insertions, 8 deletions
diff --git a/application/controllers/api.php b/application/controllers/api.php
index a7bd09f34..7557c6c99 100644
--- a/application/controllers/api.php
+++ b/application/controllers/api.php
@@ -24,11 +24,11 @@ class Api extends MY_Controller {
$major = intval(explode(".", $requested_version)[0]);
if (!preg_match("/^[a-zA-Z-_]+$/", $controller)) {
- return send_json_error_reply("Invalid controller requested");
+ return send_json_error_reply("api/invalid-controller-value", "Invalid controller requested");
}
if (!preg_match("/^[a-zA-Z-_]+$/", $function)) {
- return send_json_error_reply("Invalid function requested");
+ return send_json_error_reply("api/invalid-function-value", "Invalid function requested");
}
$namespace = "controllers\\api\\v".$major;
@@ -36,16 +36,16 @@ class Api extends MY_Controller {
$class_info = $namespace."\\api_info";
if (!class_exists($class_info) || version_compare($class_info::get_version(), $requested_version, "<")) {
- return send_json_error_reply("Requested API version is not supported");
+ return send_json_error_reply("api/version-not-supported", "Requested API version is not supported");
}
if (!class_exists($class)) {
- return send_json_error_reply("Unknown controller requested");
+ return send_json_error_reply("api/unknown-controller", "Unknown controller requested");
}
$c= new $class;
if (!method_exists($c, $function)) {
- return send_json_error_reply("Unknown function requested");
+ return send_json_error_reply("api/unknown-function", "Unknown function requested");
}
return $c->$function();
}
diff --git a/application/controllers/api/v1/file.php b/application/controllers/api/v1/file.php
index fc855f7f9..869d29ed1 100644
--- a/application/controllers/api/v1/file.php
+++ b/application/controllers/api/v1/file.php
@@ -29,7 +29,7 @@ class file extends \controllers\api\api_controller {
$errors = \service\files::verify_uploaded_files($files);
if (!empty($errors)) {
- return send_json_reply($errors, "upload-error");
+ return send_json_error_reply("file/upload-verify-failed", "Failed to verify uploaded file", $errors);
}
$limits = $this->muser->get_upload_id_limits();
diff --git a/application/helpers/filebin_helper.php b/application/helpers/filebin_helper.php
index 465f865f6..a1b540b1d 100644
--- a/application/helpers/filebin_helper.php
+++ b/application/helpers/filebin_helper.php
@@ -235,10 +235,11 @@ function send_json_reply($array, $status = "success")
$CI->output->set_output(json_encode($reply));
}
-function send_json_error_reply($message, $array = null)
+function send_json_error_reply($error_id, $message, $array = null, $status_code = 400)
{
$reply = array();
$reply["status"] = "error";
+ $reply["error_id"] = $error_id;
$reply["message"] = $message;
if ($array !== null) {
@@ -246,7 +247,7 @@ function send_json_error_reply($message, $array = null)
}
$CI =& get_instance();
- $CI->output->set_status_header(400);
+ $CI->output->set_status_header($status_code);
$CI->output->set_content_type('application/json');
$CI->output->set_output(json_encode($reply));
}