Skip to content
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

Cannot read jira.Response body #468

Open
mike-lloyd03 opened this issue Jul 25, 2022 · 2 comments
Open

Cannot read jira.Response body #468

mike-lloyd03 opened this issue Jul 25, 2022 · 2 comments
Labels
needs triage Ticket that needs triage (a proper look for classification)

Comments

@mike-lloyd03
Copy link

Describe the bug

I am abstracting the process of transitioning a Jira issue to a different state. When attempting to transition an issue from Backlog to Ready, the Jira web app raises an error telling me I need to define the story points. I'd like to handle this error when automating the process. I have the following function:

func (j *JiraIssue) UpdateStatus(statusId JiraStatus) error {
	possibleTransitions, _, _ := jiraClient.Issue.GetTransitions(j.JiraKey)
	for _, v := range possibleTransitions {
		log.Debugf("Available transition: %s %s \n", v.To.ID, v.Name)
		if v.To.ID == string(statusId) {
			resp, err := jiraClient.Issue.DoTransition(j.JiraKey, string(statusId))
			body, read_err := io.ReadAll(resp.Body)
			if read_err != nil {
				return read_err
			}
			if err != nil {
				return fmt.Errorf("%s: %v", err, string(body))
			}
			return nil
		}
	}
	return fmt.Errorf("requested status change %v is not available for this issue", statusId)
}

I am trying to read the response body if there is an error transitioning the issue. But I get the following error when trying to do so:

http: read on closed response body

How can I read the error response from the API?

Expected behavior

The jira.Response returned from DoTransition should be readable.

Your Environment

Include as many relevant details about the environment you experienced the problem in

  • go-jira version (git tag or sha): v1.15.1
  • Go version (go version): 1.18.3
  • Jira version: 8.13.11
  • Jira type (cloud or on-premise): On prem

Additional context

I'd like to be able to dynamically handle error responses that come from the API. Or at least be able to print a more helpful error message when a request to transition the issue fails.

Thanks!

@vladimir-ch
Copy link
Contributor

In case of an error, go-jira reads and decodes the response body and returns it as an error, see the code for DoTransitionWithPayloadWithContext and NewJiraError.

@andygrunwald andygrunwald added the needs triage Ticket that needs triage (a proper look for classification) label Aug 20, 2022
@andygrunwald
Copy link
Owner

andygrunwald commented Aug 21, 2022

Hey,

I am very sorry that this issue has been open for a long time with no final solution. We work on this project in our spare time, and sometimes, other priorities take over. This is the typical open source dilemma.

However, there is news: We are kicking off v2 of this library 🚀

To provide visibility, we created the Road to v2 Milestone and calling for your feedback in #489

The development will take some time; however, I hope you can benefit from the changes.
If you seek priority development for your issue + you like to sponsor it, please contact me.

What does this mean for my issue?

We will work on this issue indirectly.
This means that during the development phase, we aim to tackle it.
Maybe in a different way like it is currently handled.
Please understand that this will take a while because we are running this in our spare time.

Final words

Thanks for using this library.
If there is anything else you would like to tell us, let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Ticket that needs triage (a proper look for classification)
Projects
None yet
Development

No branches or pull requests

3 participants