roar
Loading...
Searching...
No Matches
error.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <boost/system/system_error.hpp>
6
7#include <string>
8#include <variant>
9#include <optional>
10#include <functional>
11#include <string_view>
12#include <sstream>
13
14namespace Roar
15{
19 struct Error
20 {
21 std::variant<boost::system::error_code, std::string> error;
22 std::string_view additionalInfo = {};
23
24 std::string toString() const;
25 };
26
27 template <typename StreamT>
28 StreamT& operator<<(StreamT& stream, Error error)
29 {
30 std::visit(
31 [&stream](auto const& error) {
32 stream << error;
33 },
34 error.error);
35 if (!error.additionalInfo.empty())
36 stream << ": " << error.additionalInfo;
37 return stream;
38 }
39
40 inline std::string Error::toString() const
41 {
42 std::stringstream sstr;
43 sstr << *this;
44 return sstr.str();
45 }
46}
Definition authorization.hpp:10
StreamT & operator<<(StreamT &stream, Error error)
Definition error.hpp:28
Holds errors that are produced asynchronously anywhere.
Definition error.hpp:20
std::string toString() const
Definition error.hpp:40
std::variant< boost::system::error_code, std::string > error
Definition error.hpp:21
std::string_view additionalInfo
Definition error.hpp:22