@@ -5,6 +5,7 @@ use graphql_client::{GraphQLQuery, Response};
55use reqwest:: Client ;
66use serde:: de:: DeserializeOwned ;
77use serde:: Serialize ;
8+ use tracing:: info;
89use url:: Url ;
910
1011use crate :: cli:: client:: { ClientCommand , ClientOptions , ConfigurationOptions } ;
@@ -25,13 +26,18 @@ pub async fn run_client(options: ClientOptions) {
2526 } = options;
2627
2728 let conf = match ClientConfiguration :: from_default_file ( ) . await {
28- Ok ( conf) => conf. with_host ( connection. host ) . with_auth ( connection. auth ) ,
29+ Ok ( conf) => {
30+ info ! ( "Configuration from file: {conf}" ) ;
31+ conf. with_host ( connection. host ) . with_auth ( connection. auth )
32+ }
2933 Err ( e) => {
3034 println ! ( "Could not read configuration: {e}" ) ;
3135 return ;
3236 }
3337 } ;
3438
39+ info ! ( "Configuration with CLI args included: {conf}" ) ;
40+
3541 let client = match NumtrackerClient :: from_config ( conf) . await {
3642 Ok ( client) => client,
3743 Err ( e) => {
@@ -86,14 +92,16 @@ struct ConfigureMutation;
8692
8793impl NumtrackerClient {
8894 async fn from_config ( config : ClientConfiguration ) -> Result < Self , ClientError > {
89- let host = config
90- . host
91- . unwrap_or ( Url :: parse ( "http://localhost:8000" ) . expect ( "Constant URL is valid" ) ) ;
95+ let host = config. host . unwrap_or_else ( || {
96+ info ! ( "No host specified, defaulting to localhost:8000" ) ;
97+ Url :: parse ( "http://localhost:8000" ) . expect ( "Constant URL is valid" )
98+ } ) ;
9299
93100 let auth = match config. auth {
94101 Some ( auth) => Some ( cli_auth:: get_access_token ( & auth) . await ?) ,
95102 None => None ,
96103 } ;
104+ info ! ( "Querying {host} with auth: {auth:?}" ) ;
97105 Ok ( NumtrackerClient { auth, host } )
98106 }
99107
@@ -110,7 +118,13 @@ impl NumtrackerClient {
110118 None => client,
111119 Some ( token) => client. bearer_auth ( token) ,
112120 } ;
113- client. json ( & content) . send ( ) . await ?. json ( ) . await
121+ client
122+ . json ( & content)
123+ . send ( )
124+ . await ?
125+ . error_for_status ( ) ?
126+ . json ( )
127+ . await
114128 }
115129
116130 async fn query_configuration ( self , instrument : Option < Vec < String > > ) -> Result < ( ) , ClientError > {
@@ -136,6 +150,8 @@ impl NumtrackerClient {
136150 conf. tracker_file_extension. unwrap_or( conf. instrument)
137151 ) ;
138152 }
153+ } else if data. errors . is_none ( ) {
154+ println ! ( "Query returned no data or errors" ) ;
139155 }
140156 Ok ( ( ) )
141157 }
0 commit comments