forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOcppError.h
More file actions
44 lines (37 loc) · 1.24 KB
/
OcppError.h
File metadata and controls
44 lines (37 loc) · 1.24 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
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License
#ifndef MO_OCPPERROR_H
#define MO_OCPPERROR_H
#include <MicroOcpp/Core/Operation.h>
#include <MicroOcpp/Core/Memory.h>
namespace MicroOcpp {
class NotImplemented : public Operation, public MemoryManaged {
public:
NotImplemented() : MemoryManaged("v16.CallError.", "NotImplemented") { }
const char *getErrorCode() override {
return "NotImplemented";
}
};
class MsgBufferExceeded : public Operation, public MemoryManaged {
private:
size_t maxCapacity;
size_t msgLen;
public:
MsgBufferExceeded(size_t maxCapacity, size_t msgLen) : MemoryManaged("v16.CallError.", "GenericError"), maxCapacity(maxCapacity), msgLen(msgLen) { }
const char *getErrorCode() override {
return "GenericError";
}
const char *getErrorDescription() override {
return "JSON too long or too many fields. Cannot deserialize";
}
std::unique_ptr<JsonDoc> getErrorDetails() override {
auto errDoc = makeJsonDoc(getMemoryTag(), JSON_OBJECT_SIZE(2));
JsonObject err = errDoc->to<JsonObject>();
err["max_capacity"] = maxCapacity;
err["msg_length"] = msgLen;
return errDoc;
}
};
} //end namespace MicroOcpp
#endif