-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplicationError.h
49 lines (38 loc) · 1.01 KB
/
ApplicationError.h
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
//
// Created by vaige on 14.2.2024.
//
#ifndef GROWSTUDIO_APPLICATIONERROR_H
#define GROWSTUDIO_APPLICATIONERROR_H
#include <string>
#include <nlohmann/json.hpp>
#include <chrono>
class ApplicationError
{
using Clock = std::chrono::steady_clock;
public:
ApplicationError() = default;
ApplicationError(int code, std::string message, nlohmann::json data = nlohmann::json{}, Clock::duration acuteTime = std::chrono::seconds{3})
: mCode{code}, mMessage(std::move(message)), mData{std::move(data)}, mAcuteTime{acuteTime}
{
mReceiveTime = Clock::now();
}
[[nodiscard]] bool isAcute() const
{
return Clock::now() - mReceiveTime < mAcuteTime;
}
[[nodiscard]] int code() const
{
return mCode;
}
const std::string& message()
{
return mMessage;
}
private:
int mCode{};
std::string mMessage{};
nlohmann::json mData{};
Clock::duration mAcuteTime{3};
Clock::time_point mReceiveTime{};
};
#endif //GROWSTUDIO_APPLICATIONERROR_H