diff options
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()) } |