Skip to content

Commit 7e815db

Browse files
authored
Merge pull request #385 from aedm/aedm-display-introspection-error
2 parents d309661 + 0e33081 commit 7e815db

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

graphql_client_cli/src/introspect_schema.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::error::Error;
12
use crate::CliResult;
23
use graphql_client::GraphQLQuery;
34
use reqwest::header::{HeaderMap, HeaderValue, ACCEPT, CONTENT_TYPE};
@@ -53,9 +54,17 @@ pub fn introspect_schema(
5354
if res.status().is_success() {
5455
// do nothing
5556
} else if res.status().is_server_error() {
56-
println!("server error!");
57+
return Err(Error::message("server error!".into()));
5758
} else {
58-
println!("Something else happened. Status: {:?}", res.status());
59+
let status = res.status();
60+
let error_message = match res.text() {
61+
Ok(msg) => match serde_json::from_str::<serde_json::Value>(&msg) {
62+
Ok(json) => format!("HTTP {}\n{}", status, serde_json::to_string_pretty(&json)?),
63+
Err(_) => format!("HTTP {}: {}", status, msg),
64+
},
65+
Err(_) => format!("HTTP {}", status),
66+
};
67+
return Err(Error::message(error_message));
5968
}
6069

6170
let json: serde_json::Value = res.json()?;

0 commit comments

Comments
 (0)