Skip to content

Report Jira errors returned by the REST API #10

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
34 changes: 23 additions & 11 deletions src/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License.
// * https://docs.atlassian.com/jira-software/REST/latest/

use crate::errors::JiraQueryError;
use crate::issue_model::{Issue, JqlResults};
use crate::issue_model::{Issue, JiraErrorMessages, JqlResults};

// The prefix of every subsequent REST request.
// This string comes directly after the host in the URL.
Expand Down Expand Up @@ -170,11 +170,19 @@ impl JiraInstance {
let url = self.path(&Method::Key(key), 0);

// Gets an issue by ID and deserializes the JSON to data variable
let issue = self.authenticated_get(&url).await?.json::<Issue>().await?;
let response = self.authenticated_get(&url).await?;

log::debug!("{:#?}", issue);
if response.status().is_success() {
let issue = response.json::<Issue>().await?;

Ok(issue)
log::debug!("{:#?}", issue);

Ok(issue)
} else {
Err(JiraQueryError::JiraError(
response.json::<JiraErrorMessages>().await?.error_messages,
))
}
}

/// Access several issues by their keys.
Expand Down Expand Up @@ -251,15 +259,19 @@ impl JiraInstance {
) -> Result<Vec<Issue>, JiraQueryError> {
let url = self.path(method, start_at);

let results = self
.authenticated_get(&url)
.await?
.json::<JqlResults>()
.await?;
let response = self.authenticated_get(&url).await?;

log::debug!("{:#?}", results);
if response.status().is_success() {
let results = response.json::<JqlResults>().await?;

Ok(results.issues)
log::debug!("{:#?}", results);

Ok(results.issues)
} else {
Err(JiraQueryError::JiraError(
response.json::<JiraErrorMessages>().await?.error_messages,
))
}
}

/// Access issues using a free-form JQL search.
Expand Down
2 changes: 2 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ pub enum JiraQueryError {
NoIssues,
#[error("Error in accessing the Jira REST API.")]
Request(#[from] reqwest::Error),
#[error("Error in accessing the Jira REST API: {}", .0.join(", "))]
JiraError(Vec<String>),
}
7 changes: 7 additions & 0 deletions src/issue_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,10 @@ pub struct Security {
#[serde(flatten)]
pub extra: Value,
}

/// Error messages returned by Jira REST API.
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct JiraErrorMessages {
#[serde(rename = "errorMessages")]
pub error_messages : Vec<String>
}