2016-01-18 15:33:29 +00:00
|
|
|
// Copyright (c) 2011-2016 The Cryptonote developers
|
2014-06-25 17:21:42 +00:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <system_error>
|
|
|
|
|
2015-05-27 12:08:46 +00:00
|
|
|
namespace CryptoNote {
|
2014-06-25 17:21:42 +00:00
|
|
|
namespace error {
|
|
|
|
|
|
|
|
// custom error conditions enum type:
|
|
|
|
enum NodeErrorCodes {
|
|
|
|
NOT_INITIALIZED = 1,
|
|
|
|
ALREADY_INITIALIZED,
|
|
|
|
NETWORK_ERROR,
|
|
|
|
NODE_BUSY,
|
|
|
|
INTERNAL_NODE_ERROR,
|
2015-08-19 17:06:24 +00:00
|
|
|
REQUEST_ERROR,
|
|
|
|
CONNECT_ERROR
|
2014-06-25 17:21:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// custom category:
|
|
|
|
class NodeErrorCategory : public std::error_category {
|
|
|
|
public:
|
|
|
|
static NodeErrorCategory INSTANCE;
|
|
|
|
|
2015-12-14 17:40:07 +00:00
|
|
|
virtual const char* name() const throw() override {
|
2014-06-25 17:21:42 +00:00
|
|
|
return "NodeErrorCategory";
|
|
|
|
}
|
|
|
|
|
2015-12-14 17:40:07 +00:00
|
|
|
virtual std::error_condition default_error_condition(int ev) const throw() override {
|
2014-06-25 17:21:42 +00:00
|
|
|
return std::error_condition(ev, *this);
|
|
|
|
}
|
|
|
|
|
2015-12-14 17:40:07 +00:00
|
|
|
virtual std::string message(int ev) const override {
|
2014-06-25 17:21:42 +00:00
|
|
|
switch (ev) {
|
|
|
|
case NOT_INITIALIZED: return "Object was not initialized";
|
|
|
|
case ALREADY_INITIALIZED: return "Object has been already initialized";
|
|
|
|
case NETWORK_ERROR: return "Network error";
|
|
|
|
case NODE_BUSY: return "Node is busy";
|
|
|
|
case INTERNAL_NODE_ERROR: return "Internal node error";
|
2015-04-06 16:13:07 +00:00
|
|
|
case REQUEST_ERROR: return "Error in request parameters";
|
2015-08-19 17:06:24 +00:00
|
|
|
case CONNECT_ERROR: return "Can't connect to daemon";
|
2014-06-25 17:21:42 +00:00
|
|
|
default: return "Unknown error";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
NodeErrorCategory() {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-27 12:08:46 +00:00
|
|
|
inline std::error_code make_error_code(CryptoNote::error::NodeErrorCodes e) {
|
|
|
|
return std::error_code(static_cast<int>(e), CryptoNote::error::NodeErrorCategory::INSTANCE);
|
2014-06-25 17:21:42 +00:00
|
|
|
}
|