2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
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)
7 // Official repository: https://github.com/boostorg/beast
10 #ifndef BOOST_BEAST_WEBSOCKET_IMPL_ERROR_IPP
11 #define BOOST_BEAST_WEBSOCKET_IMPL_ERROR_IPP
23 return "boost.beast.websocket";
31 switch(static_cast<error>(ev))
34 case error::closed: return "The WebSocket stream was gracefully closed at both endpoints";
35 case error::buffer_overflow: return "The WebSocket operation caused a dynamic buffer overflow";
36 case error::partial_deflate_block: return "The WebSocket stream produced an incomplete deflate block";
37 case error::message_too_big: return "The WebSocket message exceeded the locally configured limit";
39 case error::bad_http_version: return "The WebSocket handshake was not HTTP/1.1";
40 case error::bad_method: return "The WebSocket handshake method was not GET";
41 case error::no_host: return "The WebSocket handshake Host field is missing";
42 case error::no_connection: return "The WebSocket handshake Connection field is missing";
43 case error::no_connection_upgrade: return "The WebSocket handshake Connection field is missing the upgrade token";
44 case error::no_upgrade: return "The WebSocket handshake Upgrade field is missing";
45 case error::no_upgrade_websocket: return "The WebSocket handshake Upgrade field is missing the websocket token";
46 case error::no_sec_key: return "The WebSocket handshake Sec-WebSocket-Key field is missing";
47 case error::bad_sec_key: return "The WebSocket handshake Sec-WebSocket-Key field is invalid";
48 case error::no_sec_version: return "The WebSocket handshake Sec-WebSocket-Version field is missing";
49 case error::bad_sec_version: return "The WebSocket handshake Sec-WebSocket-Version field is invalid";
50 case error::no_sec_accept: return "The WebSocket handshake Sec-WebSocket-Accept field is missing";
51 case error::bad_sec_accept: return "The WebSocket handshake Sec-WebSocket-Accept field is invalid";
52 case error::upgrade_declined: return "The WebSocket handshake was declined by the remote peer";
54 case error::bad_opcode: return "The WebSocket frame contained an illegal opcode";
55 case error::bad_data_frame: return "The WebSocket data frame was unexpected";
56 case error::bad_continuation: return "The WebSocket continuation frame was unexpected";
57 case error::bad_reserved_bits: return "The WebSocket frame contained illegal reserved bits";
58 case error::bad_control_fragment: return "The WebSocket control frame was fragmented";
59 case error::bad_control_size: return "The WebSocket control frame size was invalid";
60 case error::bad_unmasked_frame: return "The WebSocket frame was unmasked";
61 case error::bad_masked_frame: return "The WebSocket frame was masked";
62 case error::bad_size: return "The WebSocket frame size was not canonical";
63 case error::bad_frame_payload: return "The WebSocket frame payload was not valid utf8";
64 case error::bad_close_code: return "The WebSocket close frame reason code was invalid";
65 case error::bad_close_size: return "The WebSocket close frame payload size was invalid";
66 case error::bad_close_payload: return "The WebSocket close frame payload was not valid utf8";
73 default_error_condition(int ev) const noexcept
75 switch(static_cast<error>(ev))
79 case error::buffer_overflow:
80 case error::partial_deflate_block:
81 case error::message_too_big:
84 case error::bad_http_version:
85 case error::bad_method:
87 case error::no_connection:
88 case error::no_connection_upgrade:
89 case error::no_upgrade:
90 case error::no_upgrade_websocket:
91 case error::no_sec_key:
92 case error::bad_sec_key:
93 case error::no_sec_version:
94 case error::bad_sec_version:
95 case error::no_sec_accept:
96 case error::bad_sec_accept:
97 case error::upgrade_declined:
98 return condition::handshake_failed;
100 case error::bad_opcode:
101 case error::bad_data_frame:
102 case error::bad_continuation:
103 case error::bad_reserved_bits:
104 case error::bad_control_fragment:
105 case error::bad_control_size:
106 case error::bad_unmasked_frame:
107 case error::bad_masked_frame:
108 case error::bad_size:
109 case error::bad_frame_payload:
110 case error::bad_close_code:
111 case error::bad_close_size:
112 case error::bad_close_payload:
113 return condition::protocol_violation;
120 name() const noexcept
122 return "boost.beast.websocket";
128 message(int cv) const
130 switch(static_cast<condition>(cv))
133 case condition::handshake_failed: return "The WebSocket handshake failed";
134 case condition::protocol_violation: return "A WebSocket protocol violation occurred";
142 make_error_code(error e)
144 static detail::error_codes const cat{};
145 return error_code{static_cast<
146 std::underlying_type<error>::type>(e), cat};
151 make_error_condition(condition c)
153 static detail::error_conditions const cat{};
154 return error_condition{static_cast<
155 std::underlying_type<condition>::type>(c), cat};