Skip to content

Commit 2eadb5a

Browse files
bors[bot]meili-botcurquiza
authored
Merge #118
118: Changes related to the next MeiliSearch release (v0.20.0) r=curquiza a=meili-bot This PR: - gathers the changes related to the next MeiliSearch release (v0.20.0) so that this package is ready when the official release is out. - should pass the tests against the [latest pre-release of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases). - might eventually contain test failures until the MeiliSearch v0.20.0 is out. ⚠️ This PR should NOT be merged until the next release of MeiliSearch (v0.20.0) is out. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/master/guides/pre-release-week.md) purpose._ Co-authored-by: meili-bot <[email protected]> Co-authored-by: Clémentine Urquizar <[email protected]>
2 parents c860dd0 + 7c04e99 commit 2eadb5a

File tree

4 files changed

+28
-33
lines changed

4 files changed

+28
-33
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ WARNING: `meilisearch-sdk` will panic if no Window is available (ex: Web extensi
139139

140140
## 🤖 Compatibility with MeiliSearch
141141

142-
This package only guarantees the compatibility with the [version v0.19.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.19.0).
142+
This package only guarantees the compatibility with the [version v0.20.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.20.0).
143143

144144
## ⚙️ Development Workflow and Contributing
145145

README.tpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ See our [Documentation](https://docs.meilisearch.com/learn/tutorials/getting_sta
4747

4848
## 🤖 Compatibility with MeiliSearch
4949

50-
This package only guarantees the compatibility with the [version v0.19.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.19.0).
50+
This package only guarantees the compatibility with the [version v0.20.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.20.0).
5151

5252
## ⚙️ Development Workflow and Contributing
5353

src/client.rs

+25-20
Original file line numberDiff line numberDiff line change
@@ -180,30 +180,17 @@ impl<'a> Client<'a> {
180180
/// #
181181
/// # futures::executor::block_on(async move {
182182
/// let client = Client::new("http://localhost:7700", "masterKey");
183-
///
184-
/// match client.health().await {
185-
/// Ok(()) => println!("server is operational"),
186-
/// Err(Error::MeiliSearchError { error_code: ErrorCode::Maintenance, .. }) => {
187-
/// eprintln!("server is in maintenance")
188-
/// },
189-
/// Err(e) => panic!("should never happen: {}", e),
190-
/// }
183+
/// let health = client.health().await.unwrap();
191184
/// # });
192185
/// ```
193-
pub async fn health(&self) -> Result<(), Error> {
194-
let r = request::<(), ()>(
186+
pub async fn health(&self) -> Result<Health, Error> {
187+
request::<serde_json::Value, Health>(
195188
&format!("{}/health", self.host),
196189
self.apikey,
197190
Method::Get,
198-
204,
191+
200,
199192
)
200-
.await;
201-
match r {
202-
// This shouldn't be an error; The status code is 200, but the request
203-
// function only supports one successful error code for some reason
204-
Err(Error::Empty) => Ok(()),
205-
e => e,
206-
}
193+
.await
207194
}
208195

209196
/// Get the private and public key.
@@ -257,6 +244,21 @@ pub struct ClientStats {
257244
pub indexes: HashMap<String, IndexStats>,
258245
}
259246

247+
/// Health of the MeiliSearch server.
248+
///
249+
/// Example:
250+
///
251+
/// ```
252+
/// # use meilisearch_sdk::{client::*, indexes::*, errors::Error};
253+
/// Health {
254+
/// status: "available".to_string(),
255+
/// };
256+
/// ```
257+
#[derive(Deserialize)]
258+
pub struct Health {
259+
pub status: String,
260+
}
261+
260262
#[derive(Deserialize)]
261263
#[serde(rename_all = "camelCase")]
262264
pub struct Keys {
@@ -265,13 +267,16 @@ pub struct Keys {
265267
}
266268

267269
/// Version of a MeiliSearch server.
270+
///
268271
/// Example:
269-
/// ```text
272+
///
273+
/// ```
274+
/// # use meilisearch_sdk::{client::*, indexes::*, errors::Error};
270275
/// Version {
271276
/// commit_sha: "b46889b5f0f2f8b91438a08a358ba8f05fc09fc1".to_string(),
272277
/// build_date: "2019-11-15T09:51:54.278247+00:00".to_string(),
273278
/// pkg_version: "0.1.1".to_string(),
274-
/// }
279+
/// };
275280
/// ```
276281
#[derive(Deserialize)]
277282
#[serde(rename_all = "camelCase")]

src/errors.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ pub enum Error {
2323
/// This Meilisearch sdk generated an invalid request (which was not sent).
2424
/// It probably comes from an invalid API key resulting in an invalid HTTP header.
2525
InvalidRequest,
26-
/// An erroring status code, but no body
27-
// This is a hack to make Client::health work, since the request module
28-
// treats anything other than the expected status as an error. Since 204 is
29-
// specified, a successful status of 200 is treated as an error with an
30-
// empty body.
31-
Empty,
3226

3327
/// The http client encountered an error.
3428
#[cfg(not(target_arch = "wasm32"))]
@@ -268,8 +262,7 @@ impl std::fmt::Display for Error {
268262
Error::UnreachableServer => write!(fmt, "The MeiliSearch server can't be reached."),
269263
Error::InvalidRequest => write!(fmt, "Unable to generate a valid HTTP request. It probably comes from an invalid API key."),
270264
Error::ParseError(e) => write!(fmt, "Error parsing response JSON: {}", e),
271-
Error::HttpError(e) => write!(fmt, "HTTP request failed: {}", e),
272-
Error::Empty => write!(fmt, "An error occured without a message"),
265+
Error::HttpError(e) => write!(fmt, "HTTP request failed: {}", e)
273266
}
274267
}
275268
}
@@ -278,9 +271,6 @@ impl std::error::Error for Error {}
278271

279272
impl From<&serde_json::Value> for Error {
280273
fn from(json: &serde_json::Value) -> Error {
281-
if json.is_null() {
282-
return Error::Empty;
283-
}
284274

285275
let message = json
286276
.get("message")

0 commit comments

Comments
 (0)