From 5d9d0ccd85b45fbfae4b52029c7a69dc01a57c27 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 4 Jul 2020 13:37:27 +0100 Subject: [PATCH] wip --- src/error.rs | 1 - src/http.rs | 22 ++++++++++++++++++++++ src/lib.rs | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/http.rs 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; -- 2.30.2