danicoin/src/HTTP/HttpParserErrorCodes.h

54 lines
1.4 KiB
C
Raw Normal View History

// Copyright (c) 2011-2016 The Cryptonote developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2015-05-27 12:08:46 +00:00
#pragma once
#include <string>
#include <system_error>
namespace CryptoNote {
namespace error {
enum HttpParserErrorCodes {
STREAM_NOT_GOOD = 1,
END_OF_STREAM,
UNEXPECTED_SYMBOL,
EMPTY_HEADER
};
// custom category:
class HttpParserErrorCategory : public std::error_category {
public:
static HttpParserErrorCategory INSTANCE;
virtual const char* name() const throw() override {
2015-05-27 12:08:46 +00:00
return "HttpParserErrorCategory";
}
virtual std::error_condition default_error_condition(int ev) const throw() override {
2015-05-27 12:08:46 +00:00
return std::error_condition(ev, *this);
}
virtual std::string message(int ev) const override {
2015-05-27 12:08:46 +00:00
switch (ev) {
case STREAM_NOT_GOOD: return "The stream is not good";
case END_OF_STREAM: return "The stream is ended";
case UNEXPECTED_SYMBOL: return "Unexpected symbol";
case EMPTY_HEADER: return "The header name is empty";
default: return "Unknown error";
}
}
private:
HttpParserErrorCategory() {
}
};
} //namespace error
2015-07-30 15:22:07 +00:00
} //namespace CryptoNote
2015-05-27 12:08:46 +00:00
inline std::error_code make_error_code(CryptoNote::error::HttpParserErrorCodes e) {
return std::error_code(static_cast<int>(e), CryptoNote::error::HttpParserErrorCategory::INSTANCE);
}