Refactor WebSocket errors (API Change):

fix #949

* New error codes are introduced for WebSocket failures

* More verbose messages for error codes

* Error codes are mapped to conditions for ease of testing

* error::failed and error::handshake_failed are deprecated (don't use)

Actions Required:

* Code which explicitly compares error_code values against the
  constant `websocket::error::handshake_failed` should compare
  against `websocket::condition::handshake_failed` instead.

* Code which explicitly compares error_code values against the
  constant `websocket::error::failed` should compare
  against `websocket::condition::protocol_violation` instead.
This commit is contained in:
Vinnie Falco
2018-01-01 17:49:19 -08:00
parent 08a9ed4c25
commit cc43b46c42
19 changed files with 705 additions and 346 deletions

View File

@@ -25,32 +25,53 @@ public:
auto const ec = make_error_code(e);
ec.category().name();
BEAST_EXPECT(! ec.message().empty());
#if 0
BEAST_EXPECT(std::addressof(ec.category()) ==
std::addressof(detail::get_error_category()));
BEAST_EXPECT(detail::get_error_category().equivalent(
static_cast<std::underlying_type<error>::type>(e),
ec.category().default_error_condition(
static_cast<std::underlying_type<error>::type>(e))));
BEAST_EXPECT(detail::get_error_category().equivalent(
ec, static_cast<std::underlying_type<error>::type>(e)));
#endif
BEAST_EXPECT(ec != condition::handshake_failed);
BEAST_EXPECT(ec != condition::protocol_violation);
}
void check(error e, condition c)
void check(condition c, error e)
{
BEAST_EXPECT(error_code{e} == c);
auto const ec = make_error_code(e);
BEAST_EXPECT(ec.category().name() != nullptr);
BEAST_EXPECT(! ec.message().empty());
BEAST_EXPECT(ec == c);
}
void run() override
{
check(error::closed);
check(error::failed);
check(error::handshake_failed);
check(error::buffer_overflow);
check(error::partial_deflate_block);
check(error::message_too_big);
check(error::handshake_failed, condition::handshake_failed);
check(condition::protocol_violation, error::bad_opcode);
check(condition::protocol_violation, error::bad_data_frame);
check(condition::protocol_violation, error::bad_continuation);
check(condition::protocol_violation, error::bad_reserved_bits);
check(condition::protocol_violation, error::bad_control_fragment);
check(condition::protocol_violation, error::bad_control_size);
check(condition::protocol_violation, error::bad_unmasked_frame);
check(condition::protocol_violation, error::bad_masked_frame);
check(condition::protocol_violation, error::bad_size);
check(condition::protocol_violation, error::bad_frame_payload);
check(condition::protocol_violation, error::bad_close_code);
check(condition::protocol_violation, error::bad_close_size);
check(condition::protocol_violation, error::bad_close_payload);
check(condition::handshake_failed, error::bad_http_version);
check(condition::handshake_failed, error::bad_method);
check(condition::handshake_failed, error::no_host);
check(condition::handshake_failed, error::no_connection);
check(condition::handshake_failed, error::no_connection_upgrade);
check(condition::handshake_failed, error::no_upgrade);
check(condition::handshake_failed, error::no_upgrade_websocket);
check(condition::handshake_failed, error::no_sec_key);
check(condition::handshake_failed, error::bad_sec_key);
check(condition::handshake_failed, error::no_sec_version);
check(condition::handshake_failed, error::bad_sec_version);
check(condition::handshake_failed, error::no_sec_accept);
check(condition::handshake_failed, error::bad_sec_accept);
check(condition::handshake_failed, error::upgrade_declined);
}
};