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

Project.find('non-existing-project') raises HTTP error #293

Closed
kali-hernandez opened this issue Jun 21, 2018 · 3 comments
Closed

Project.find('non-existing-project') raises HTTP error #293

kali-hernandez opened this issue Jun 21, 2018 · 3 comments

Comments

@kali-hernandez
Copy link

Trying to use find method for Project class, with a non existing project name, will raise an HTTPError rather than an empty result set:

[:get, "/rest/api/2/project/NONEXIST", nil, {"Accept"=>"application/json"}]
#<Net::HTTPNotFound 404  readbody=true>
/Library/Ruby/Gems/2.3.0/gems/jira-ruby-1.5.0/lib/jira/request_client.rb:18:in `request': JIRA::HTTPError

The code on request_client.rb seems to be doing this on purpose:
https://github.com/sumoheavy/jira-ruby/blob/master/lib/jira/request_client.rb#L16

When manually requesting the url above in the browser, I'm getting a 404 http status code but with a json response including a descriptive message:
HTTP/2.0 404 Not Found

{"errorMessages":["No project could be found with key 'NONEXIST'."],"errors":{}}

Seems to me like the API is purposely returning http 404 code for meaning that a project is not found, while the request_client.rb code is treating such 404 as an HTTP error when it isn't. The reply json should be equally parsed and passed back to the Project.find method which in turn should probably return an empty list.

@kali-hernandez
Copy link
Author

The consequence of this issue is that I cannot use the method Project.try() unless I know for sure that the project I'm looking for does indeed exist. I can work around this by requesting the whole set of projects with Project.all and then iterating each element searching for the name, but that is suboptimal at least.

@rmf34
Copy link

rmf34 commented Oct 22, 2018

I started work on some more transparent error handling for this project over the weekend. Will push up and mention this and other issues when I have something working and tests passing.

@bobbrodie
Copy link
Member

Hey everyone, I know it's been a while but I am commenting on old issues while closing them out. The latest version in master, soon to be released, attaches the error message in the HTTPError.

I've written about this here: #432 (comment).

When I request a project that doesn't exist, I am receiving an HTTPError as expected and if you inspect the HTTPError with something like this:

begin
  client.Project.find('NOEXIST')
rescue => e
  puts JSON.parse(e.response.body.inspect)
end

Then you'll see:

{"errorMessages":["No project could be found with key 'NOEXIST'."],"errors":{}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants