-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathport_error.hpp
44 lines (35 loc) · 881 Bytes
/
port_error.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
#include <string>
#include <system_error>
#ifdef ESP8266
#include <ESPAsyncTCP.h>
#elif defined(ESP32)
#include "AsyncTCP.h"
#else
#error "platform not support"
#endif
namespace esp_rpc {
enum class ErrorType : err_t {};
class ErrorCategory : public std::error_category {
public:
static ErrorCategory& instance() {
static ErrorCategory instance;
return instance;
}
public:
ErrorCategory() = default;
const char* name() const noexcept override {
return "lwip error";
}
std::string message(int ev) const override {
return ((AsyncClient*)(nullptr))->errorToString((err_t)ev);
}
};
std::error_code make_error_code(ErrorType e) {
return {static_cast<int>(e), ErrorCategory::instance()};
}
} // namespace esp_rpc
namespace std {
template <>
struct is_error_code_enum<esp_rpc::ErrorType> : public true_type {};
} // namespace std