summaryrefslogtreecommitdiff
path: root/src/requests/start.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/requests/start.rs')
-rw-r--r--src/requests/start.rs27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/requests/start.rs b/src/requests/start.rs
index 1a8cb6c..30f65b9 100644
--- a/src/requests/start.rs
+++ b/src/requests/start.rs
@@ -1,6 +1,7 @@
1use reqwest::StatusCode;
1use serde::Deserialize; 2use serde::Deserialize;
2 3
3use crate::{config::SETTINGS, error::CliError, default_headers}; 4use crate::{config::SETTINGS, error::CliError, default_headers, ErrorResponse};
4 5
5pub fn start(id: String) -> Result<(), CliError> { 6pub fn start(id: String) -> Result<(), CliError> {
6 let res = reqwest::blocking::Client::new() 7 let res = reqwest::blocking::Client::new()
@@ -15,13 +16,27 @@ pub fn start(id: String) -> Result<(), CliError> {
15 format!(r#"{{"id": "{}"}}"#, id) 16 format!(r#"{{"id": "{}"}}"#, id)
16 ) 17 )
17 .send() 18 .send()
18 .map_err(CliError::Reqwest)? 19 .map_err(CliError::Reqwest)?;
19 .text();
20 20
21 let res = serde_json::from_str::<StartResponse>(&res.map_err(CliError::Reqwest)?).map_err(CliError::Serde)?; 21 match res.status() {
22 StatusCode::OK => {
23 let body = serde_json::from_str::<StartResponse>(
24 &res.text().map_err(CliError::Reqwest)?
25 )
26 .map_err(CliError::Serde)?;
27
28 if body.boot {
29 println!("successfully started {}", body.id);
30 }
31 },
32 _ => {
33 let body = serde_json::from_str::<ErrorResponse>(
34 &res.text().map_err(CliError::Reqwest)?
35 )
36 .map_err(CliError::Serde)?;
22 37
23 if res.boot { 38 println!("got error: {}", body.error);
24 println!("successfully started {}", res.id); 39 }
25 } 40 }
26 41
27 Ok(()) 42 Ok(())