src/error.cpp

100.0% Lines (48/48) 100.0% List of functions (7/7) 93.9% Branches (46/49)
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 13x error_category::message(int ev) const
27 {
28
4/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 1 time.
13x 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
9/9
✓ 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.
9x 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 default:
54
1/1
✓ Branch 1 taken 1 time.
2x return "unknown error";
55 }
56 }
57
58 std::error_condition
59 10x error_category::default_error_condition(int ev) const noexcept
60 {
61
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)
62 4x return condition::client_error;
63
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)
64 4x return condition::server_error;
65 2x return std::error_condition(ev, *this);
66 }
67
68 //----------------------------------------------------------
69
70 char const*
71 1x condition_category::name() const noexcept
72 {
73 1x return "boost.burl.condition";
74 }
75
76 std::string
77 3x condition_category::message(int ev) const
78 {
79
3/3
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
3x switch(static_cast<condition>(ev))
80 {
81 1x case condition::client_error:
82
1/1
✓ Branch 1 taken 1 time.
2x return "HTTP client error";
83 1x case condition::server_error:
84
1/1
✓ Branch 1 taken 1 time.
2x return "HTTP server error";
85 1x default:
86
1/1
✓ Branch 1 taken 1 time.
2x return "unknown condition";
87 }
88 }
89
90 //----------------------------------------------------------
91
92 std::error_category const&
93 52x burl_category() noexcept
94 {
95
3/4
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 45 times.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
52x static error_category const cat{};
96 52x return cat;
97 }
98
99 std::error_category const&
100 22x burl_condition_category() noexcept
101 {
102
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{};
103 22x return cat;
104 }
105
106 } // namespace burl
107 } // namespace boost
108