chiark / gitweb /
wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 4 Jul 2020 12:37:27 +0000 (13:37 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 4 Jul 2020 12:37:27 +0000 (13:37 +0100)
src/error.rs
src/http.rs [new file with mode: 0644]
src/lib.rs

index fd92c2fa195d5e7c4d9a23d70bf788bba5ea955b..7aabe52cbff59c29e507ec44eeeb978667882994 100644 (file)
@@ -29,7 +29,6 @@ impl<X> From<PoisonError<X>> for OnlineError {
   fn from(_: PoisonError<X>) -> OnlineError { GameCorrupted }
 }
 
-
 pub trait ById {
   type Id;
   type Entry;
diff --git a/src/http.rs b/src/http.rs
new file mode 100644 (file)
index 0000000..528bbcf
--- /dev/null
@@ -0,0 +1,22 @@
+
+use rocket::request::Request;
+use rocket::response::{Response,Responder};
+
+use crate::imports::*;
+
+impl<'r> Responder<'r> for OnlineError {
+  #[throws(Status)]
+  fn respond_to(self, req: &Request) -> Response<'r> {
+    let msg = format!("Online-layer error\n{:?}\n{}\n", self, self);
+    use rocket::http::Status;//::Continue;
+    use OnlineError::*;
+    let s = rocket::http::Status::Ok;
+    let status = match self {
+      GameCorrupted => Status::InternalServerError,
+      NoClient | NoPlayer => Status::NotFound,
+    };
+    let mut resp = Responder::respond_to(msg,req).unwrap();
+    resp.set_status(status);
+    resp
+  }
+}
index 1a8627dfa0f22880abbd885a41d17ddcd6f64ff1..3c365e958426ea02c06eeeb951a019115b707b60 100644 (file)
@@ -7,3 +7,4 @@ pub mod keydata;
 pub mod updates;
 pub mod sse;
 pub mod error;
+pub mod http;