Добавлены структуры исключений

This commit is contained in:
Антон
2025-09-29 08:48:42 +03:00
parent 049fcf0f48
commit 0ef4c7e46c
2 changed files with 30 additions and 11 deletions
+26 -1
View File
@@ -1,3 +1,6 @@
#include <mysqlx/xdevapi.h>
#include <mysqlx/common/api.h>
#include "IExecutor.h"
#include "IController.h"
#include "Controller.h"
@@ -7,6 +10,9 @@
#include "../DAO/IUserDAO.h"
#include "../DAO/IAuthDAO.h"
#include "./../helpers/helpers.h"
#include "./../exceptions/exception400_bad_request.h"
#include "./../exceptions/exception409_conflict.h"
#include "./../exceptions/exception422_unprocessable_entity.h"
namespace uad
{
@@ -84,7 +90,26 @@ public:
{
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));
}
}
}