mirror of
https://github.com/KingDuckZ/kamokan.git
synced 2024-11-23 00:33:44 +00:00
Report errors from lua into the response.
This commit is contained in:
parent
51088333ed
commit
ecb44e725a
5 changed files with 35 additions and 4 deletions
|
@ -46,6 +46,9 @@ namespace kamokan {
|
|||
m_pastie_info =
|
||||
storage().retrieve_pastie(token, settings().as<uint32_t>("max_token_length"));
|
||||
|
||||
if (m_pastie_info.error)
|
||||
return make_error_redirect(m_pastie_info);
|
||||
|
||||
if (this->token_invalid()) {
|
||||
assert(this->pastie_not_found());
|
||||
return make_error_redirect(ErrorReasons::InvalidToken);
|
||||
|
@ -89,4 +92,24 @@ namespace kamokan {
|
|||
else
|
||||
return std::string();
|
||||
}
|
||||
|
||||
tawashi::HttpHeader GeneralPastieResponse::make_error_redirect (const Storage::RetrievedPastie& parRetrievedInfo) {
|
||||
using tawashi::ErrorReasons;
|
||||
|
||||
assert(parRetrievedInfo.error);
|
||||
const auto& err = *parRetrievedInfo.error;
|
||||
|
||||
try {
|
||||
return make_error_redirect(ErrorReasons::_from_string(err.c_str()));
|
||||
}
|
||||
catch (const std::runtime_error& e) {
|
||||
auto statuslog = spdlog::get("statuslog");
|
||||
statuslog->error(
|
||||
"Retrieved info generated an unexpected error: \"{}\"; exception raised: \"{}\"",
|
||||
err,
|
||||
e.what()
|
||||
);
|
||||
return make_error_redirect(ErrorReasons::UnknownReason);
|
||||
}
|
||||
}
|
||||
} //namespace kamokan
|
||||
|
|
|
@ -39,6 +39,8 @@ namespace kamokan {
|
|||
virtual tawashi::HttpHeader on_general_pastie_process() = 0;
|
||||
virtual void on_general_mustache_prepare (std::string&& parPastie, mstch::map& parContext) = 0;
|
||||
std::string default_pastie_lang() override;
|
||||
using Response::make_error_redirect;
|
||||
tawashi::HttpHeader make_error_redirect (const Storage::RetrievedPastie& parRetrievedInfo);
|
||||
|
||||
Storage::RetrievedPastie m_pastie_info;
|
||||
};
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
local token = KEYS[1]
|
||||
local result = redis.call("HMGET", token, "pastie", "selfdes", "lang")
|
||||
if false == result[1] then
|
||||
return redis.error_reply("PastieNotFound")
|
||||
end
|
||||
|
||||
local selfdes = 0
|
||||
local deleted = 0
|
||||
if result[2] == 1 then
|
||||
|
|
|
@ -170,14 +170,11 @@ namespace kamokan {
|
|||
}
|
||||
|
||||
auto Storage::retrieve_pastie (const boost::string_view& parToken, uint32_t parMaxTokenLen) const -> RetrievedPastie {
|
||||
using opt_string_list = redis::IncRedis::opt_string_list;
|
||||
|
||||
RetrievedPastie retval;
|
||||
retval.valid_token = is_valid_token(parToken, parMaxTokenLen);
|
||||
if (not retval.valid_token)
|
||||
return retval;
|
||||
|
||||
|
||||
redis::Script retrieve = m_redis->command().make_script(boost::string_view(g_load_script, g_load_script_size - 1));
|
||||
auto batch = m_redis->command().make_batch();
|
||||
retrieve.run(batch, std::make_tuple(parToken), std::make_tuple());
|
||||
|
@ -185,7 +182,11 @@ namespace kamokan {
|
|||
if (raw_replies.empty())
|
||||
return retval;
|
||||
|
||||
assert(not raw_replies.front().is_error());
|
||||
if (raw_replies.front().is_error()) {
|
||||
retval.error =
|
||||
boost::make_optional<std::string>(get_error_string(raw_replies.front()).message());
|
||||
return retval;
|
||||
}
|
||||
auto pastie_reply = get_array(raw_replies.front());
|
||||
|
||||
retval.pastie = get_string(pastie_reply[0]);
|
||||
|
|
|
@ -46,6 +46,7 @@ namespace kamokan {
|
|||
|
||||
boost::optional<std::string> pastie;
|
||||
boost::optional<std::string> lang;
|
||||
boost::optional<std::string> error;
|
||||
bool self_destructed;
|
||||
bool valid_token;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue