Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: RoverClientError::CouldNotConnect #518

Merged
merged 3 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,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()
}
Comment on lines +78 to +82
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty friggin neat if i do say so myself

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is neat!

)]
CouldNotConnect {
source: reqwest::Error,
url: Option<Url>,
},

/// Encountered an error sending the request.
#[error("encountered an error while sending a request")]
#[error(transparent)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i changed this to transparent so that it would just print out the whole error message from reqwest. they're a bit verbose but they at least give some info to the user that we were obfuscating previously. i imagine as we see these crop up we can add more of our own error types

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 accepting connections is spelled correctly".to_string()


};
Expand Down