-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathexceptions.h
More file actions
100 lines (77 loc) · 2.44 KB
/
exceptions.h
File metadata and controls
100 lines (77 loc) · 2.44 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
This file is part of FlashMQ (https://www.flashmq.org)
Copyright (C) 2021-2023 Wiebe Cazemier
FlashMQ is free software: you can redistribute it and/or modify
it under the terms of The Open Software License 3.0 (OSL-3.0).
See LICENSE for license details.
*/
#ifndef EXCEPTIONS_H
#define EXCEPTIONS_H
#include <optional>
#include <stdexcept>
#include <sstream>
#include "types.h"
#define API __attribute__((visibility("default")))
// Because exceptions are (potentially) visible to plugins, we want to make sure to avoid symbol collisions, so using their own namespace.
namespace FlashMQ
{
/**
* @brief The ProtocolError class is handled by the error handler in the worker threads and is used to make decisions about if and how
* to inform a client and log the message.
*
* It's mainly meant for errors that can be communicated with MQTT packets.
*/
class API ProtocolError : public std::runtime_error
{
public:
const ReasonCodes reasonCode;
ProtocolError(const std::string &msg, ReasonCodes reasonCode = ReasonCodes::UnspecifiedError) : std::runtime_error(msg),
reasonCode(reasonCode)
{
}
};
class API BadClientException : public std::runtime_error
{
std::optional<int> mLogLevel;
public:
BadClientException(const std::string &msg, int logLevel=-1) : std::runtime_error(msg)
{
if (logLevel >= 0)
this->mLogLevel = logLevel;
}
std::optional<int> getLogLevel() const { return this->mLogLevel; }
};
class API NotImplementedException : public std::runtime_error
{
public:
NotImplementedException(const std::string &msg) : std::runtime_error(msg) {}
};
class API FatalError : public std::runtime_error
{
public:
FatalError(const std::string &msg) : std::runtime_error(msg) {}
};
class API ConfigFileException : public std::runtime_error
{
public:
ConfigFileException(const std::string &msg) : std::runtime_error(msg) {}
ConfigFileException(std::ostringstream oss) : std::runtime_error(oss.str()) {}
};
class API pluginException : public std::runtime_error
{
public:
pluginException(const std::string &msg) : std::runtime_error(msg) {}
};
class API BadWebsocketVersionException : public std::runtime_error
{
public:
BadWebsocketVersionException(const std::string &msg) : std::runtime_error(msg) {}
};
class API BadHttpRequest : public std::runtime_error
{
public:
BadHttpRequest(const std::string &msg) : std::runtime_error(msg) {}
};
}
using namespace FlashMQ;
#endif // EXCEPTIONS_H