From: Ian Jackson Date: Sat, 4 Jul 2020 12:37:27 +0000 (+0100) Subject: wip X-Git-Tag: otter-0.2.0~1471 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=5d9d0ccd85b45fbfae4b52029c7a69dc01a57c27;p=otter.git wip --- diff --git a/src/error.rs b/src/error.rs index fd92c2fa..7aabe52c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -29,7 +29,6 @@ impl From> for OnlineError { fn from(_: PoisonError) -> OnlineError { GameCorrupted } } - pub trait ById { type Id; type Entry; diff --git a/src/http.rs b/src/http.rs new file mode 100644 index 00000000..528bbcf4 --- /dev/null +++ b/src/http.rs @@ -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 + } +} diff --git a/src/lib.rs b/src/lib.rs index 1a8627df..3c365e95 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,3 +7,4 @@ pub mod keydata; pub mod updates; pub mod sse; pub mod error; +pub mod http;