src/error.cpp

100.0% Lines (50/50) 100.0% List of functions (7/7) 94.1% Branches (48/51)
error.cpp
f(x) Functions (7)
Line Branch TLA Hits Source Code
1 //
2 // Copyright (c) 2026 Mohammad Nejati
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/cppalliance/burl
8 //
9
10 #include <boost/burl/error.hpp>
11
12 #include <boost/http/status.hpp>
13
14 namespace boost
15 {
16 namespace burl
17 {
18
19 char const*
20 1x error_category::name() const noexcept
21 {
22 1x return "boost.burl";
23 }
24
25 std::string
26 14x error_category::message(int ev) const
27 {
28
4/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 1 time.
14x if(ev >= 400 && ev < 600)
29 {
30 4x auto status = static_cast<http::status>(ev);
31
2/2
✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
8x return "HTTP " + std::to_string(ev) + " " +
32
3/3
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
12x std::string(http::to_string(status));
33 }
34
35
10/10
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 1 time.
✓ Branch 9 taken 1 time.
10x switch(static_cast<error>(ev))
36 {
37 1x case error::unsupported_url_scheme:
38
1/1
✓ Branch 1 taken 1 time.
2x return "unsupported URL scheme";
39 1x case error::too_many_redirects:
40
1/1
✓ Branch 1 taken 1 time.
2x return "too many redirects";
41 1x case error::bad_redirect_response:
42
1/1
✓ Branch 1 taken 1 time.
2x return "bad redirect response";
43 1x case error::file_changed:
44
1/1
✓ Branch 1 taken 1 time.
2x return "file size changed during read";
45 1x case error::unsupported_proxy_scheme:
46
1/1
✓ Branch 1 taken 1 time.
2x return "unsupported proxy scheme";
47 1x case error::proxy_connect_failed:
48
1/1
✓ Branch 1 taken 1 time.
2x return "proxy could not connect to the target";
49 1x case error::proxy_auth_failed:
50
1/1
✓ Branch 1 taken 1 time.
2x return "proxy authentication failed";
51 1x case error::proxy_unsupported_version:
52
1/1
✓ Branch 1 taken 1 time.
2x return "unsupported proxy protocol version";
53 1x case error::body_size_mismatch:
54
1/1
✓ Branch 1 taken 1 time.
2x return "request body size did not match content length";
55 1x default:
56
1/1
✓ Branch 1 taken 1 time.
2x return "unknown error";
57 }
58 }
59
60 std::error_condition
61 10x error_category::default_error_condition(int ev) const noexcept
62 {
63
4/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 4 times.
10x if(ev >= 400 && ev < 500)
64 4x return condition::client_error;
65
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
6x if(ev >= 500 && ev < 600)
66 4x return condition::server_error;
67 2x return std::error_condition(ev, *this);
68 }
69
70 //----------------------------------------------------------
71
72 char const*
73 1x condition_category::name() const noexcept
74 {
75 1x return "boost.burl.condition";
76 }
77
78 std::string
79 3x condition_category::message(int ev) const
80 {
81
3/3
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
3x switch(static_cast<condition>(ev))
82 {
83 1x case condition::client_error:
84
1/1
✓ Branch 1 taken 1 time.
2x return "HTTP client error";
85 1x case condition::server_error:
86
1/1
✓ Branch 1 taken 1 time.
2x return "HTTP server error";
87 1x default:
88
1/1
✓ Branch 1 taken 1 time.
2x return "unknown condition";
89 }
90 }
91
92 //----------------------------------------------------------
93
94 std::error_category const&
95 61x burl_category() noexcept
96 {
97
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 53 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
61x static error_category const cat{};
98 61x return cat;
99 }
100
101 std::error_category const&
102 22x burl_condition_category() noexcept
103 {
104
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 20 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
22x static condition_category const cat{};
105 22x return cat;
106 }
107
108 } // namespace burl
109 } // namespace boost
110