diff --git a/src/endpoints_handlers/AuthLoginExecutor.h b/src/endpoints_handlers/AuthLoginExecutor.h index e8f07c1..ff2a10b 100644 --- a/src/endpoints_handlers/AuthLoginExecutor.h +++ b/src/endpoints_handlers/AuthLoginExecutor.h @@ -50,7 +50,8 @@ public: } catch (const system::system_error& err) { - throw session_exception(http::status::bad_request, "cannot deserialize json"); + BOOST_LOG_TRIVIAL(info) << "POST /api/v1/Auth/Login - Response 500: Cannot deserialize json"; + throw session_exception(http::status::internal_server_error, "Cannot deserialize json"); } @@ -59,6 +60,7 @@ public: if (login.empty() || password.empty()) { + BOOST_LOG_TRIVIAL(info) << "POST /api/v1/Auth/Login - Response 422: Login or password are empty"; throw session_exception(http::status::unprocessable_entity, "Login or password are empty"s); } @@ -66,6 +68,7 @@ public: if (!maybe_user.has_value() && maybe_user.value().hashed_password != HashPassword(password)) { + BOOST_LOG_TRIVIAL(info) << "POST /api/v1/Auth/Login - Response 403: Incorrect login or password"; throw session_exception(http::status::forbidden,"Incorrect login or password"); } const std::string token = GenerateUUID(); diff --git a/src/endpoints_handlers/AuthLogoutExecutor.h b/src/endpoints_handlers/AuthLogoutExecutor.h index f543d0c..35ccdd2 100644 --- a/src/endpoints_handlers/AuthLogoutExecutor.h +++ b/src/endpoints_handlers/AuthLogoutExecutor.h @@ -1,4 +1,5 @@ #pragma once +#include #include #include @@ -35,6 +36,8 @@ public: using namespace boost::beast; using namespace std::string_literals; + BOOST_LOG_TRIVIAL(info) << "POST /api/v1/Auth/Logout - Request"; + const auto body = req.body(); value req_json; @@ -44,6 +47,7 @@ public: } catch (const system::system_error& err) { + BOOST_LOG_TRIVIAL(error) << "POST /api/v1/Auth/Logout - Response 500: Cannot deserialize json"; throw session_exception(http::status::internal_server_error, "cannot deserialize json"s); } @@ -51,7 +55,8 @@ public: if (!auth_dao_->Logout(token)) { - throw session_exception(http::status::bad_request, "token is not authorized"s); + BOOST_LOG_TRIVIAL(error) << "POST /api/v1/Auth/Logout - Response 400: Token is not authorized"; + throw session_exception(http::status::bad_request, "Token is not authorized"s); } http::response res{http::status::ok, req.version()}; diff --git a/src/endpoints_handlers/AuthRegistrationExecutor.h b/src/endpoints_handlers/AuthRegistrationExecutor.h index 7506f18..f659856 100644 --- a/src/endpoints_handlers/AuthRegistrationExecutor.h +++ b/src/endpoints_handlers/AuthRegistrationExecutor.h @@ -1,4 +1,5 @@ #pragma once +#include #include #include @@ -32,6 +33,8 @@ public: using namespace boost::beast; using namespace std::string_literals; + BOOST_LOG_TRIVIAL(info) << "POST /api/v1/Auth/Registration - Request"; + const auto& body = req.body(); value req_json; @@ -41,7 +44,8 @@ public: } catch (const system::system_error& err) { - throw session_exception(http::status::bad_request, "cannot deserialize json"); + BOOST_LOG_TRIVIAL(error) << "POST /api/v1/Auth/Registration - Response 500: Cannot deserialize json"; + throw session_exception(http::status::internal_server_error, "Cannot deserialize json"); } const std::string login = req_json.as_object().at("login").as_string().c_str(); @@ -49,6 +53,7 @@ public: if (!ValidateLogin(login) || !ValidatePassword(password)) { + BOOST_LOG_TRIVIAL(error) << "POST /api/v1/Auth/Registration - Response 422: Validations failed. Login should have length from 3 to 50. Password from 5 characters length."; throw session_exception( http::status::unprocessable_entity, "Validations failed. Login should have length from 3 to 50. Password from 5 characters length."s @@ -57,7 +62,8 @@ public: if (user_dao_->GetByLogin(login).has_value()) { - throw session_exception(http::status::conflict, "user with login "s + login + " exists"s); + BOOST_LOG_TRIVIAL(error) << "POST /api/v1/Auth/Registration - Response 409: "s + "User with login "s + login + " exists"s; + throw session_exception(http::status::conflict, "User with login "s + login + " exists"s); } user user;