Skip to content

Commit d455dc4

Browse files
committed
Rename client error variants
1 parent d5027b2 commit d455dc4

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

src/clients.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@ pub struct TiledClient {
1818
impl TiledClient {
1919
async fn request<T: DeserializeOwned>(&self, endpoint: &str) -> ClientResult<T> {
2020
println!("Requesting data from tiled");
21-
2221
let url = self.address.join(endpoint)?;
23-
2422
let response = reqwest::get(url).await?;
25-
let json = response.json().await?;
26-
27-
Ok(serde_json::from_value(json)?)
23+
Ok(response.json().await?)
2824
}
2925
}
3026
impl Client for TiledClient {
@@ -35,38 +31,31 @@ impl Client for TiledClient {
3531

3632
#[derive(Debug)]
3733
pub enum ClientError {
38-
Parse(url::ParseError),
39-
Reqwest(reqwest::Error),
40-
Serde(serde_json::Error),
41-
Io(std::io::Error),
34+
InvalidPath(url::ParseError),
35+
ServerError(reqwest::Error),
36+
InvalidResponse(serde_json::Error),
4237
}
4338
impl From<url::ParseError> for ClientError {
4439
fn from(err: url::ParseError) -> ClientError {
45-
ClientError::Parse(err)
40+
ClientError::InvalidPath(err)
4641
}
4742
}
4843
impl From<reqwest::Error> for ClientError {
4944
fn from(err: reqwest::Error) -> ClientError {
50-
ClientError::Reqwest(err)
45+
ClientError::ServerError(err)
5146
}
5247
}
5348
impl From<serde_json::Error> for ClientError {
5449
fn from(err: serde_json::Error) -> ClientError {
55-
ClientError::Serde(err)
56-
}
57-
}
58-
impl From<std::io::Error> for ClientError {
59-
fn from(err: std::io::Error) -> ClientError {
60-
ClientError::Io(err)
50+
ClientError::InvalidResponse(err)
6151
}
6252
}
6353
impl std::fmt::Display for ClientError {
6454
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6555
match *self {
66-
ClientError::Parse(ref err) => write!(f, "Parse error: {}", err),
67-
ClientError::Reqwest(ref err) => write!(f, "Request error: {}", err),
68-
ClientError::Serde(ref err) => write!(f, "Serde error: {}", err),
69-
ClientError::Io(ref err) => write!(f, "IO Error: {}", err),
56+
ClientError::InvalidPath(ref err) => write!(f, "Invalid URL path: {}", err),
57+
ClientError::ServerError(ref err) => write!(f, "Tiled server error: {}", err),
58+
ClientError::InvalidResponse(ref err) => write!(f, "Could not read response: {}", err),
7059
}
7160
}
7261
}

0 commit comments

Comments
 (0)