From 12c96ceaeaabe0aa7d0d2c70497886d9a5610f10 Mon Sep 17 00:00:00 2001 From: Vika Date: Tue, 19 Jul 2022 05:27:39 +0300 Subject: kittybox-indieauth: convert Error into axum::response::Response This requires the `axum` feature to be enabled, to prevent unwanted dependencies (e.g. in client apps or when using a different framework, since the library doesn't concern itself with I/O) --- kittybox-rs/indieauth/src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'kittybox-rs/indieauth/src') diff --git a/kittybox-rs/indieauth/src/lib.rs b/kittybox-rs/indieauth/src/lib.rs index b461fea..cb99146 100644 --- a/kittybox-rs/indieauth/src/lib.rs +++ b/kittybox-rs/indieauth/src/lib.rs @@ -144,6 +144,7 @@ pub enum GrantResponse { #[serde(skip_serializing_if = "Option::is_none")] profile: Option, access_token: String, + // TODO replace with std::time::Duration #[serde(skip_serializing_if = "Option::is_none")] expires_in: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -176,6 +177,7 @@ pub struct TokenData { pub me: Url, pub client_id: Url, pub scope: Scopes, + // TODO replace these two with std::time::SystemTime #[serde(skip_serializing_if = "Option::is_none")] pub exp: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -359,6 +361,18 @@ impl std::fmt::Display for self::Error { } } +#[cfg(feature = "axum")] +impl axum_core::response::IntoResponse for self::Error { + fn into_response(self) -> axum_core::response::Response { + use http::StatusCode; + + (StatusCode::BAD_REQUEST, + [("Content-Type", "application/json")], + serde_json::to_vec(&self).unwrap()) + .into_response() + } +} + #[cfg(test)] mod tests { use super::*; -- cgit 1.4.1