WIP: 404 handling

This commit is contained in:
R.Y.A.N 2025-03-07 02:46:54 +01:00
parent ad1b8a6dd5
commit c96300a2f4
Signed by: R.Y.A.N
GPG Key ID: 3BD93EABD1407B82
2 changed files with 23 additions and 5 deletions

View File

@ -11,14 +11,28 @@ namespace seafire::resources
{
auto rep = common::invoke(resource, req, &R::get);
auto select = [&]() -> decltype(rep)
{
if constexpr (representation::traits::is_optional_representation_v<decltype(rep)>) {
if (!rep) {
return std::nullopt;
}
return representation::select(*rep, accepted_type);
}
else {
return representation::select(rep, accepted_type);
}
};
auto selected_rep = select();
if (!selected_rep) {
res.send(server::common_error_t::not_found);
return;
}
auto selected_rep = representation::select(*rep, accepted_type);
if (!check_preconditions(req, res, selected_rep))
if (!check_preconditions(req, res, *selected_rep))
return;
namespace rfc7231 = protocol::rfc7231;
@ -41,7 +55,7 @@ namespace seafire::resources
status = 201;
bool const send_content = kind != get_kind_t::head;
representation::send(req, res, status, selected_rep, send_content);
representation::send(req, res, status, *selected_rep, send_content);
}
} // namespace seafire::resources

View File

@ -43,6 +43,10 @@ namespace seafire::resources::traits
typename common::traits::function_traits<decltype(&R::get)>::return_type
>
||
representation::traits::is_representation_v<
typename common::traits::function_traits<decltype(&R::get)>::return_type
>
||
representation::traits::is_optional_representation_v<
typename common::traits::function_traits<decltype(&R::get)>::return_type
>