From a5500d4fb350951e010042d91e3a79e12ce1e14a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Mon, 29 Sep 2025 18:42:20 +0300 Subject: [PATCH] =?UTF-8?q?Logout=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B2=D0=B5?= =?UTF-8?q?=D0=B4=D0=B5=D0=BD=20=D0=BD=D0=B0=20=D1=81=D0=B8=D1=81=D1=82?= =?UTF-8?q?=D0=B5=D0=BC=D1=83=20=D0=B8=D1=81=D0=BA=D0=BB=D1=8E=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B9=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/endpoints_handlers/AuthLogoutExecutor.h | 50 +++++++-------------- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 7d19b6a..0cd85ee 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ null ``` ##### Errors -* `401 BAD_CREDENTIALS` — Такого токена не существует(B3) +* `400 BAD_REQUEST` — Такого токена не существует(B3) ### 10. Используемые сущности ДБ * users(uuid(PK), login(unique), hashed_password) diff --git a/src/endpoints_handlers/AuthLogoutExecutor.h b/src/endpoints_handlers/AuthLogoutExecutor.h index a5ba174..f0f73e9 100644 --- a/src/endpoints_handlers/AuthLogoutExecutor.h +++ b/src/endpoints_handlers/AuthLogoutExecutor.h @@ -38,47 +38,29 @@ public: const auto body = req.body(); value req_json; - value response_body; - response_body.emplace_object(); - try { req_json = json::parse(body); - - const std::string token = req_json.as_object().at("token").as_string().c_str(); - - if (!auth_dao_->Logout(token)) - { - http::response res{http::status::bad_request, req.version()}; - - response_body.as_object().emplace("Result", "token is not authorized"); - - res.body() = json::serialize(response_body); - res.set(http::field::content_type, "application/json"); - res.content_length(res.body().size()); - - return res; - } - - http::response res{http::status::ok, req.version()}; - - res.body() = "true"s; - res.set(http::field::content_type, "application/json"); - res.content_length(res.body().size()); - - return res; } catch (const system::system_error& err) { - http::response res{http::status::bad_request, req.version()}; - response_body.as_object().emplace("Result", "cannot deserialize json"); - - res.body() = serialize(response_body); - res.set(http::field::content_type, "application/json"); - res.content_length(res.body().size()); - - return res; + throw exception400_bad_request("cannot deserialize json"s); } + + const std::string token = req_json.as_object().at("token").as_string().c_str(); + + if (!auth_dao_->Logout(token)) + { + throw exception400_bad_request("token is not authorized"s); + } + + http::response res{http::status::ok, req.version()}; + + res.body() = "null"s; + res.set(http::field::content_type, "application/json"); + res.content_length(res.body().size()); + + return res; } }; }