aboutsummaryrefslogtreecommitdiff
path: root/src/client/gateway/error.rs
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-21 19:17:57 -0800
committerAustin Hellyer <[email protected]>2016-11-21 19:17:57 -0800
commit6b1a83111d4d9cc2ef2f4eed1ee8f58d45525078 (patch)
treea6f0303ebcf4a474f603aaa5c8fff67409d42a17 /src/client/gateway/error.rs
parentAdd support for creating embed images (diff)
downloadserenity-6b1a83111d4d9cc2ef2f4eed1ee8f58d45525078.tar.xz
serenity-6b1a83111d4d9cc2ef2f4eed1ee8f58d45525078.zip
Re-organize the client module
Re-organize the client module, creating a `gateway` submodule, and splitting the connection into separate files in it. The connection was a conglomeration of a number of purposes, most of which are actually used elsewhere in the library and/or exposed to the user. Thus, it makes sense to separate each item in a gateway-specific module. By splitting the client module further, this is a re-organization for preliminary RPC support WRT the Client. Additionally, rename the Connection struct to a Shard. The Connection itself was not the actual connection, and was a higher-level interface to the real connection logic. A Shard is a more accurate representation of what it actually is.
Diffstat (limited to 'src/client/gateway/error.rs')
-rw-r--r--src/client/gateway/error.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/client/gateway/error.rs b/src/client/gateway/error.rs
new file mode 100644
index 0000000..fb44d3f
--- /dev/null
+++ b/src/client/gateway/error.rs
@@ -0,0 +1,27 @@
+use std::fmt::{self, Display};
+
+#[derive(Clone, Debug)]
+pub enum Error {
+ /// The connection closed
+ Closed(Option<u16>, String),
+ /// Expected a Hello during a handshake
+ ExpectedHello,
+ /// Expected a Ready or an InvalidateSession
+ InvalidHandshake,
+}
+
+impl Display for Error {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
+ Error::Closed(s, ref v) => {
+ f.write_str(&format!("Connection closed {:?}: {:?}", s, v))
+ },
+ Error::ExpectedHello => {
+ f.write_str("Expected Hello during handshake")
+ },
+ Error::InvalidHandshake => {
+ f.write_str("Expected Ready or InvalidateSession")
+ },
+ }
+ }
+}