generated from Sithas/conan_template
Добавлены структуры исключений
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "IExecutor.h"
|
#include "IExecutor.h"
|
||||||
#include "../DAO/IUserDAO.h"
|
#include "../DAO/IUserDAO.h"
|
||||||
|
#include "../exceptions/exception400_bad_request.h"
|
||||||
|
|
||||||
namespace uad
|
namespace uad
|
||||||
{
|
{
|
||||||
@@ -37,24 +38,17 @@ public:
|
|||||||
value req_json;
|
value req_json;
|
||||||
value response_body;
|
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)
|
catch (const system::system_error& err)
|
||||||
{
|
{
|
||||||
http::response<ResponseType> res{http::status::bad_request, req.version()};
|
throw exception400_bad_request("cannot deserialize json");
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response_body.emplace_object();
|
||||||
|
|
||||||
const std::string login = req_json.as_object().at("login").as_string().c_str();
|
const std::string login = req_json.as_object().at("login").as_string().c_str();
|
||||||
const std::string password = req_json.as_object().at("password").as_string().c_str();
|
const std::string password = req_json.as_object().at("password").as_string().c_str();
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
#include <mysqlx/xdevapi.h>
|
||||||
|
#include <mysqlx/common/api.h>
|
||||||
|
|
||||||
#include "IExecutor.h"
|
#include "IExecutor.h"
|
||||||
#include "IController.h"
|
#include "IController.h"
|
||||||
#include "Controller.h"
|
#include "Controller.h"
|
||||||
@@ -7,6 +10,9 @@
|
|||||||
#include "../DAO/IUserDAO.h"
|
#include "../DAO/IUserDAO.h"
|
||||||
#include "../DAO/IAuthDAO.h"
|
#include "../DAO/IAuthDAO.h"
|
||||||
#include "./../helpers/helpers.h"
|
#include "./../helpers/helpers.h"
|
||||||
|
#include "./../exceptions/exception400_bad_request.h"
|
||||||
|
#include "./../exceptions/exception409_conflict.h"
|
||||||
|
#include "./../exceptions/exception422_unprocessable_entity.h"
|
||||||
|
|
||||||
namespace uad
|
namespace uad
|
||||||
{
|
{
|
||||||
@@ -84,7 +90,26 @@ public:
|
|||||||
{
|
{
|
||||||
IRouteExecutor& executor = *maybe_executor_ptr.value();
|
IRouteExecutor& executor = *maybe_executor_ptr.value();
|
||||||
|
|
||||||
return send(executor(std::move(req)));
|
try
|
||||||
|
{
|
||||||
|
boost::beast::http::response<ResponseType> res = executor(std::move(req));
|
||||||
|
|
||||||
|
return send(std::move(res));
|
||||||
|
}
|
||||||
|
catch (const exception400_bad_request& e)
|
||||||
|
{
|
||||||
|
boost::beast::http::response<ResponseType> res{boost::beast::http::status::bad_request, req.version()};
|
||||||
|
boost::json::value response_body;
|
||||||
|
|
||||||
|
response_body.emplace_object();
|
||||||
|
response_body.as_object().emplace("Result", e.what());
|
||||||
|
|
||||||
|
res.body() = serialize(response_body);
|
||||||
|
res.set(boost::beast::http::field::content_type, "application/json");
|
||||||
|
res.content_length(res.body().size());
|
||||||
|
|
||||||
|
return send(std::move(res));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user