Logout переведен на систему исключений вместо возврата

This commit is contained in:
Антон
2025-09-29 18:42:20 +03:00
parent e0bb9025b1
commit eb187025eb
2 changed files with 17 additions and 35 deletions
+1 -1
View File
@@ -141,7 +141,7 @@ null
``` ```
##### Errors ##### Errors
* `401 BAD_CREDENTIALS` — Такого токена не существует(B3) * `400 BAD_REQUEST` — Такого токена не существует(B3)
### 10. Используемые сущности ДБ ### 10. Используемые сущности ДБ
* users(uuid(PK), login(unique), hashed_password) * users(uuid(PK), login(unique), hashed_password)
+7 -25
View File
@@ -38,47 +38,29 @@ public:
const auto body = req.body(); const auto body = req.body();
value req_json; value req_json;
value response_body;
response_body.emplace_object();
try try
{ {
req_json = json::parse(body); req_json = json::parse(body);
}
catch (const system::system_error& err)
{
throw exception400_bad_request("cannot deserialize json"s);
}
const std::string token = req_json.as_object().at("token").as_string().c_str(); const std::string token = req_json.as_object().at("token").as_string().c_str();
if (!auth_dao_->Logout(token)) if (!auth_dao_->Logout(token))
{ {
http::response<ResponseType> res{http::status::bad_request, req.version()}; throw exception400_bad_request("token is not authorized"s);
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<ResponseType> res{http::status::ok, req.version()}; http::response<ResponseType> res{http::status::ok, req.version()};
res.body() = "true"s; res.body() = "null"s;
res.set(http::field::content_type, "application/json"); res.set(http::field::content_type, "application/json");
res.content_length(res.body().size()); res.content_length(res.body().size());
return res; return res;
} }
catch (const system::system_error& err)
{
http::response<ResponseType> 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;
}
}
}; };
} }