forked from glynos/cpp-netlib
-
Notifications
You must be signed in to change notification settings - Fork 425
/
client_errors.cpp
79 lines (54 loc) · 1.77 KB
/
client_errors.cpp
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
// Copyright (C) 2013 by Glyn Matthews
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <network/config.hpp>
#include <network/http/v2/client/client_errors.hpp>
#include <string>
namespace network {
namespace http {
namespace v2 {
class client_category_impl : public std::error_category {
public:
client_category_impl() = default;
virtual ~client_category_impl() noexcept;
virtual const char *name() const noexcept;
virtual std::string message(int ev) const;
};
client_category_impl::~client_category_impl() noexcept {
}
const char *client_category_impl::name() const noexcept {
static const char name[] = "client_error";
return name;
}
std::string client_category_impl::message(int ev) const {
switch (client_error(ev)) {
case client_error::invalid_request:
return "Invalid HTTP request.";
case client_error::invalid_response:
return "Invalid HTTP response.";
default:
break;
}
return "Unknown client error.";
}
const std::error_category &client_category() {
static client_category_impl client_category;
return client_category;
}
std::error_code make_error_code(client_error e) {
return std::error_code(static_cast<int>(e), client_category());
}
invalid_url::invalid_url()
: std::invalid_argument("Requires HTTP or HTTPS URL.") {
}
invalid_url::~invalid_url() noexcept {
}
client_exception::client_exception(client_error error)
: std::system_error(make_error_code(error)) {
}
client_exception::~client_exception() noexcept {
}
} // namespace v2
} // namespace network
} // namespace network