Skip to content

Commit

Permalink
feat: RoverClientError::CouldNotConnect
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper committed May 6, 2021
1 parent fbdb753 commit 8b0bea0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
[pull/484]: https://github.com/apollographql/rover/pull/484
[issue/169]: https://github.com/apollographql/rover/issues/169

- **Better error messages for HTTP errors - [EverlastingBugstopper], [issue/489] [pull/518]**

Previously, Rover obfuscated the information about HTTP errors that occurred. Now, if something goes wrong between your machine and any HTTP server, you'll get some more information about what exactly went wrong.

[Author]: https://github.com/EverlastingBugstopper
[pull/PR #]: https://github.com/apollographql/rover/pull/518
[issue/Issue #]: https://github.com/apollographql/rover/issues/489

## 🐛 Fixes
## 🛠 Maintenance

Expand Down
12 changes: 11 additions & 1 deletion crates/rover-client/src/blocking/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@ impl Client {
.post(&self.uri)
.headers(h)
.json(&body)
.send()?
.send()
.map_err(|e| {
if e.is_connect() {
RoverClientError::CouldNotConnect {
url: e.url().cloned(),
source: e,
}
} else {
e.into()
}
})?
.error_for_status()?;

Client::handle_response::<Q>(response)
Expand Down
21 changes: 17 additions & 4 deletions crates/rover-client/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use reqwest::Url;
use thiserror::Error;

/// RoverClientError represents all possible failures that can occur during a client request.
Expand All @@ -18,15 +19,15 @@ pub enum RoverClientError {
},

/// Tried to build a [HeaderMap] with an invalid header name.
#[error("invalid header name")]
#[error("Invalid header name")]
InvalidHeaderName(#[from] reqwest::header::InvalidHeaderName),

/// Tried to build a [HeaderMap] with an invalid header value.
#[error("invalid header value")]
#[error("Invalid header value")]
InvalidHeaderValue(#[from] reqwest::header::InvalidHeaderValue),

/// Invalid JSON in response body.
#[error("could not parse JSON")]
#[error("Could not parse JSON")]
InvalidJson(#[from] serde_json::Error),

/// Encountered an error handling the received response.
Expand Down Expand Up @@ -73,8 +74,20 @@ pub enum RoverClientError {
frontend_url_root: String,
},

#[error("Could not connect to {}.",
if let Some(url) = .url {
url.to_string()
} else {
"Unknown URL".to_string()
}
)]
CouldNotConnect {
source: reqwest::Error,
url: Option<Url>,
},

/// Encountered an error sending the request.
#[error("encountered an error while sending a request")]
#[error(transparent)]
SendRequest(#[from] reqwest::Error),

/// when someone provides a bad graph/variant combination or isn't
Expand Down
5 changes: 4 additions & 1 deletion src/error/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ impl From<&mut anyhow::Error> for Metadata {
RoverClientError::InvalidJson(_)
| RoverClientError::InvalidHeaderName(_)
| RoverClientError::InvalidHeaderValue(_)
| RoverClientError::SendRequest(_)
| RoverClientError::MalformedResponse { null_field: _ }
| RoverClientError::InvalidSeverity => (Some(Suggestion::SubmitIssue), None),
RoverClientError::SendRequest(_) => (None, None),
RoverClientError::CouldNotConnect { .. } => {
(Some(Suggestion::CheckServerConnection), None)
}
RoverClientError::NoCompositionPublishes {
graph: _,
composition_errors,
Expand Down
2 changes: 2 additions & 0 deletions src/error/metadata/suggestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub enum Suggestion {
CheckKey,
ProperKey,
NewUserNoProfiles,
CheckServerConnection,
}

impl Display for Suggestion {
Expand Down Expand Up @@ -115,6 +116,7 @@ impl Display for Suggestion {
)
}
Suggestion::Adhoc(msg) => msg.to_string(),
Suggestion::CheckServerConnection => "Make sure the endpoint is accepting connections.".to_string()


};
Expand Down

0 comments on commit 8b0bea0

Please sign in to comment.