Skip to content

Commit

Permalink
fix: doctests for listeners and made apierror fields public
Browse files Browse the repository at this point in the history
  • Loading branch information
Mettwasser committed Jun 10, 2024
1 parent 9437b10 commit c61b3eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
18 changes: 8 additions & 10 deletions src/worldstate/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::worldstate::listener::Change;

use super::error::{ApiError, ApiErrorResponse};

use super::models::base::{Endpoint, Model, RTArray, RTObject};
Expand Down Expand Up @@ -152,10 +150,10 @@ impl Client {
/// /// This function will be called once a fissure updates.
/// /// This will send a request to the corresponding endpoint once every 30s
/// /// and compare the results for changes.
/// async fn on_fissure_update(fissure: Change<'_, Fissure>) {
/// match fissure {
/// Change::Added(fissure) => println!("Fissure ADDED : {fissure:?}"),
/// Change::Removed(fissure) => println!("Fissure REMOVED : {fissure:?}"),
/// async fn on_fissure_update(fissure: &Fissure, change: Change) {
/// match change {
/// Change::Added => println!("Fissure ADDED : {fissure:?}"),
/// Change::Removed => println!("Fissure REMOVED : {fissure:?}"),
/// }
/// }
///
Expand Down Expand Up @@ -350,11 +348,11 @@ impl Client {
/// _s: String,
/// }
///
/// async fn on_fissure_update(state: Arc<MyState>, fissure: Change<'_, Fissure>) {
/// async fn on_fissure_update(state: Arc<MyState>, fissure: &Fissure, change: Change) {
/// println!("STATE : {state:?}");
/// match fissure {
/// Change::Added(f) => println!("FISSURE ADDED : {f:?}"),
/// Change::Removed(f) => println!("FISSURE REMOVED : {f:?}"),
/// match change {
/// Change::Added => println!("FISSURE ADDED : {fissure:?}"),
/// Change::Removed => println!("FISSURE REMOVED : {fissure:?}"),
/// }
/// }
///
Expand Down
4 changes: 2 additions & 2 deletions src/worldstate/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use serde::Deserialize;
#[error("")]
pub struct ApiErrorResponse {
/// The error message
error: String,
pub error: String,
// The status code returned
code: u16,
pub code: u16,
}

#[derive(Debug, thiserror::Error)]
Expand Down
12 changes: 11 additions & 1 deletion src/worldstate/models/arbitration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,17 @@ mod test {

match client.fetch_using_lang::<Arbitration>(Language::ZH).await {
Ok(_arbitration) => Ok(()),
Err(why) => Err(why),
Err(why) => {
if let ApiError::ApiError(error) = why {
if error.code == 404 {
Ok(())
} else {
Err(ApiError::ApiError(error))
}
} else {
Err(why)
}
}
}
}
}

0 comments on commit c61b3eb

Please sign in to comment.