From 3ed0d97dc68795a051e1fbf0677b9879ce1d0513 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Fri, 9 Jan 2026 21:28:29 -0600 Subject: [PATCH] mergerfs_webui.cpp --- src/mergerfs_webui.cpp | 52 +++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/mergerfs_webui.cpp b/src/mergerfs_webui.cpp index 8d50d7b1..42e534a4 100644 --- a/src/mergerfs_webui.cpp +++ b/src/mergerfs_webui.cpp @@ -384,31 +384,41 @@ _post_kvs_key(const httplib::Request &req_, return; } - int rv; - fs::path mount; - std::string key; - std::string val; - - key = req_.path_params.at("key"); - val = json::parse(req_.body); - mount = req_.get_param_value("mount"); - - rv = mergerfs::api::set_kv(mount,key,val); - - json j; - if(rv >= 0) + try { - j["result"] = "success"; - res_.set_content(j.dump(), - "application/json"); + int rv; + fs::path mount; + std::string key; + std::string val; + + key = req_.path_params.at("key"); + val = json::parse(req_.body); + mount = req_.get_param_value("mount"); + + rv = mergerfs::api::set_kv(mount,key,val); + + json j; + if(rv >= 0) + { + j["result"] = "success"; + res_.set_content(j.dump(), + "application/json"); + } + else + { + res_.status = 400; + j["result"] = "error"; + j["error"] = ::_generate_error(mount,key,val,rv); + res_.set_content(j.dump(), + "application/json"); + } } - else + catch(const std::exception &e) { + fmt::print("{}\n",e.what()); res_.status = 400; - j["result"] = "error"; - j["error"] = ::_generate_error(mount,key,val,rv); - res_.set_content(j.dump(), - "application/json"); + res_.set_content("invalid json", + "text/plain"); } }