diff options
| author | Zeyla Hellyer <[email protected]> | 2017-06-21 13:57:55 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-06-21 13:57:55 -0700 |
| commit | f86be081e2681bcf003332fde5d47c727143ddb8 (patch) | |
| tree | 30e6b7d54b394f979554375a1d3cfdf1a87f4c22 /src | |
| parent | Add 'wait' parameter to http::execute_webhook (diff) | |
| download | serenity-f86be081e2681bcf003332fde5d47c727143ddb8.tar.xz serenity-f86be081e2681bcf003332fde5d47c727143ddb8.zip | |
Extract Discord close codes to constants
Diffstat (limited to 'src')
| -rw-r--r-- | src/constants.rs | 47 | ||||
| -rw-r--r-- | src/gateway/shard.rs | 26 |
2 files changed, 60 insertions, 13 deletions
diff --git a/src/constants.rs b/src/constants.rs index 148b348..1d4ec88 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -121,3 +121,50 @@ impl VoiceOpCode { } } } + +pub mod close_codes { + /// Unknown error; try reconnecting? + /// + /// Can reconnect. + pub const UNKNOWN_ERROR: u16 = 4000; + /// Invalid Gateway OP Code. + /// + /// Can resume. + pub const UNKNOWN_OPCODE: u16 = 4001; + /// An invalid payload was sent. + /// + /// Can resume. + pub const DECODE_ERROR: u16 = 4002; + /// A payload was sent prior to identifying. + /// + /// Cannot reconnect. + pub const NOT_AUTHENTICATED: u16 = 4003; + /// The account token sent with the identify payload was incorrect. + /// + /// Cannot reconnect. + pub const AUTHENTICATION_FAILED: u16 = 4004; + /// More than one identify payload was sent. + /// + /// Can reconnect. + pub const ALREADY_AUTHENTICATED: u16 = 4005; + /// The sequence sent when resuming the session was invalid. + /// + /// Can reconnect. + pub const INVALID_SEQUENCE: u16 = 4007; + /// Payloads were being sent too quickly. + /// + /// Can resume. + pub const RATE_LIMITED: u16 = 4008; + /// A session timed out. + /// + /// Can reconnect. + pub const SESSION_TIMEOUT: u16 = 4009; + /// An invalid shard when identifying was sent. + /// + /// Cannot reconnect. + pub const INVALID_SHARD: u16 = 4010; + /// The session would have handled too many guilds. + /// + /// Cannot reconnect. + pub const SHARDING_REQUIRED: u16 = 4011; +} diff --git a/src/gateway/shard.rs b/src/gateway/shard.rs index 38faa6b..ecc837a 100644 --- a/src/gateway/shard.rs +++ b/src/gateway/shard.rs @@ -12,7 +12,7 @@ use websocket::stream::sync::AsTcpStream; use websocket::sync::client::{Client, ClientBuilder}; use websocket::sync::stream::{TcpStream, TlsStream}; use websocket::WebSocketError; -use ::constants::{self, OpCode}; +use ::constants::{self, OpCode, close_codes}; use ::internal::prelude::*; use ::internal::ws_impl::SenderExt; use ::model::event::{Event, GatewayEvent}; @@ -442,36 +442,36 @@ impl Shard { } match num { - Some(4001) => warn!("Sent invalid opcode"), - Some(4002) => warn!("Sent invalid message"), - Some(4003) => { + Some(close_codes::UNKNOWN_OPCODE) => warn!("Sent invalid opcode"), + Some(close_codes::DECODE_ERROR) => warn!("Sent invalid message"), + Some(close_codes::NOT_AUTHENTICATED) => { warn!("Sent no authentication"); return Err(Error::Gateway(GatewayError::NoAuthentication)); }, - Some(4004) => { + Some(close_codes::AUTHENTICATION_FAILED) => { warn!("Sent invalid authentication"); return Err(Error::Gateway(GatewayError::InvalidAuthentication)); }, - Some(4005) => warn!("Already authenticated"), - Some(4007) => { + Some(close_codes::ALREADY_AUTHENTICATED) => warn!("Already authenticated"), + Some(close_codes::INVALID_SEQUENCE) => { warn!("[Shard {:?}] Sent invalid seq: {}", self.shard_info, self.seq); self.seq = 0; }, - Some(4008) => warn!("Gateway ratelimited"), - Some(4010) => { + Some(close_codes::RATE_LIMITED) => warn!("Gateway ratelimited"), + Some(close_codes::INVALID_SHARD) => { warn!("Sent invalid shard data"); return Err(Error::Gateway(GatewayError::InvalidShardData)); }, - Some(4011) => { + Some(close_codes::SHARDING_REQUIRED) => { error!("Shard has too many guilds"); return Err(Error::Gateway(GatewayError::OverloadedShard)); }, - Some(4006) | Some(4009) => { + Some(4006) | Some(close_codes::SESSION_TIMEOUT) => { info!("[Shard {:?}] Invalid session", self.shard_info); self.session_id = None; @@ -485,8 +485,8 @@ impl Shard { _ => {}, } - let resume = num.map(|num| { - num != 1000 && num != 4004 && self.session_id.is_some() + let resume = num.map(|x| { + x != 1000 && x != close_codes::AUTHENTICATION_FAILED && self.session_id.is_some() }).unwrap_or(false); if resume { |