Rework the client error handling

This commit is contained in:
Chunting Gu
2019-06-10 12:00:57 +08:00
parent c2a009f68a
commit 8c09189b14
16 changed files with 158 additions and 199 deletions
+7 -32
View File
@@ -1,9 +1,8 @@
#include "webcc/globals.h"
#include <iostream>
#include <map>
#include "webcc/version.h"
namespace webcc {
// -----------------------------------------------------------------------------
@@ -47,37 +46,13 @@ std::string FromExtension(const std::string& extension,
// -----------------------------------------------------------------------------
const char* DescribeError(Error error) {
switch (error) {
case kSchemaError:
return "Schema error";
case kHostResolveError:
return "Host resolve error";
case kEndpointConnectError:
return "Endpoint connect error";
case kHandshakeError:
return "Handshake error";
case kSocketReadError:
return "Socket read error";
case kSocketWriteError:
return "Socket write error";
case kHttpError:
return "HTTP error";
case kFileIOError:
return "File IO error";
default:
return "";
}
}
Exception::Exception(Error error, const std::string& details, bool timeout)
: error_(error), msg_(DescribeError(error)), timeout_(timeout) {
if (!details.empty()) {
msg_ += " (" + details + ")";
}
if (timeout) {
msg_ += " (timeout)";
std::ostream& operator<<(std::ostream& os, const Error& error) {
os << std::to_string(static_cast<int>(error.code()));
os << ": " << error.message();
if (error.timeout()) {
os << " (timeout)";
}
return os;
}
} // namespace webcc