diff options
author | Vika <vika@fireburn.ru> | 2024-12-03 08:46:31 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2024-12-03 08:46:31 +0300 |
commit | 5f45525ad06c87d28c845204b75c0e6b70ba0320 (patch) | |
tree | fc9390f7217c5695140d8cf6b6efcc6a36d397d7 /src/micropub.rs | |
parent | ef6b0f6ee3b769356f7bc852eb240e26f2d895cf (diff) | |
download | bowl-5f45525ad06c87d28c845204b75c0e6b70ba0320.tar.zst |
Small tweaks for compatibility with Kittybox's inconsistent implementation
I need to fix that, but that'll take a small refactor of Kittybox. I want things to work and be liberal in what I accept, so I put in some shortcuts.
Diffstat (limited to 'src/micropub.rs')
-rw-r--r-- | src/micropub.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/micropub.rs b/src/micropub.rs index dbd8f9a..04fa893 100644 --- a/src/micropub.rs +++ b/src/micropub.rs @@ -4,7 +4,7 @@ pub use kittybox_util::micropub::{Error as MicropubError, Config, QueryType}; #[derive(Debug)] pub struct Client { micropub: String, - access_token: String, + pub access_token: String, http: soup::Session, } @@ -43,6 +43,9 @@ impl Client { headers.append("Authorization", &format!("Bearer {}", self.access_token)); let body = self.http.send_and_read_future(&exch, glib::Priority::DEFAULT).await?; + if exch.status() == soup::Status::Unauthorized { + return Err(MicropubError::from(kittybox_util::micropub::ErrorKind::NotAuthorized).into()) + } Ok(serde_json::from_slice(&body)?) } @@ -69,8 +72,17 @@ impl Client { soup::Status::InternalServerError | soup::Status::BadGateway | soup::Status::ServiceUnavailable => { todo!("micropub server is down") }, + soup::Status::Unauthorized => { + Err(MicropubError::from(kittybox_util::micropub::ErrorKind::NotAuthorized).into()) + } _ => { - let error = serde_json::from_slice::<MicropubError>(&body)?; + let error = match serde_json::from_slice::<MicropubError>(&body) { + Ok(error) => error, + Err(err) => { + tracing::debug!("Error serializing body: {}", String::from_utf8_lossy(&body)); + Err(err)? + } + }; Err(error.into()) } |