Skip to content

Commit

Permalink
fix: IMS job creation returns CSM error msg is request failt
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Sopena Ballesteros committed Jul 2, 2024
1 parent 428dbb2 commit 384804e
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/ims/job/http_client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use serde_json::Value;

use crate::error::Error;

use super::{
r#struct::{JobPostRequest, SshContainer},
utils::wait_ims_job_to_finish,
Expand All @@ -14,7 +16,7 @@ pub async fn post_customize(
image_root_archive_name: &str,
artifact_id: &str,
public_key_id: &str,
) -> Result<Value, reqwest::Error> {
) -> Result<Value, Error> {
let ssh_container = SshContainer {
name: "jail".to_string(),
jail: true,
Expand Down Expand Up @@ -54,15 +56,28 @@ pub async fn post_customize(

let api_url = shasta_base_url.to_owned() + "/ims/v3/jobs";

client
let response = client
.post(api_url)
.bearer_auth(shasta_token)
.json(&ims_job)
.send()
.await?
.error_for_status()?
.json()
.await
.map_err(|error| Error::NetError(error))?;

if response.status().is_success() {
// Make sure we return a vec if user requesting a single value
response
.json()
.await
.map_err(|error| Error::NetError(error))
} else {
let payload = response
.json::<Value>()
.await
.map_err(|error| Error::NetError(error))?;

Err(Error::CsmError(payload))
}
}

/// Creates an IMS job, this method is asynchronous, meaning, it will returns when the server
Expand Down

0 comments on commit 384804e

Please sign in to comment.