-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.cpp
More file actions
56 lines (49 loc) · 1.38 KB
/
errors.cpp
File metadata and controls
56 lines (49 loc) · 1.38 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
#include "errors.hpp"
namespace { // anonymous namespace
struct ESPErrorCategory : std::error_category
{
const char* name() const noexcept override;
std::string message(int error_value) const override;
};
const char *ESPErrorCategory::name() const noexcept
{
return "ESP";
}
std::string ESPErrorCategory::message(int error_value) const
{
return esp_err_to_name(error_value);
}
const ESPErrorCategory theESPErrorCategory {};
struct RuntimeErrorCategory : std::error_category
{
const char* name() const noexcept override;
std::string message(int error_value) const override;
};
const char *RuntimeErrorCategory::name() const noexcept
{
return "Runtime";
}
std::string RuntimeErrorCategory::message(int error_value) const
{
switch (static_cast<RuntimeError>(error_value))
{
case RuntimeError::MQTTInitializationFailed:
return "Initializing MQTT client failed";
case RuntimeError::MQTTPublishFailed:
return "Publishing MQTT data failed";
case RuntimeError::MQTTSubscribeFailed:
return "Subscribing to MQTT topic failed";
default:
return "Unknown error";
}
}
const RuntimeErrorCategory theRuntimeErrorCategory {};
} // anonymous namespace
std::error_code make_error_code(ESPError e)
{
return {static_cast<int32_t>(e), theESPErrorCategory};
}
std::error_code make_error_code(RuntimeError e)
{
return {static_cast<int32_t>(e), theRuntimeErrorCategory};
}