audio_trans/nosql_lib/redis/inc/drogon/nosql/RedisException.h

62 lines
1.3 KiB
C
Raw Permalink Normal View History

2025-04-07 11:31:21 +08:00
/**
*
* @file RedisException.h
* @author An Tao
*
* Copyright 2018, An Tao. All rights reserved.
* https://github.com/an-tao/drogon
* Use of this source code is governed by a MIT license
* that can be found in the License file.
*
* Drogon
*
*/
#pragma once
#include <exception>
#include <functional>
namespace drogon
{
namespace nosql
{
enum class RedisErrorCode
{
kNone = 0,
kUnknown,
kConnectionBroken,
kNoConnectionAvailable,
kRedisError,
kInternalError,
kTransactionCancelled,
kBadType,
kTimeout
};
class RedisException final : public std::exception
{
public:
const char *what() const noexcept override
{
return message_.data();
}
RedisErrorCode code() const
{
return code_;
}
RedisException(RedisErrorCode code, const std::string &message)
: message_(message), code_(code)
{
}
RedisException(RedisErrorCode code, std::string &&message)
: message_(std::move(message)), code_(code)
{
}
RedisException() = delete;
private:
std::string message_;
RedisErrorCode code_{RedisErrorCode::kNone};
};
using RedisExceptionCallback = std::function<void(const RedisException &)>;
} // namespace nosql
} // namespace drogon