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

JIRA::HTTPError: JIRA::HTTPError #332

Closed
ankurjoshi54 opened this issue Apr 16, 2019 · 16 comments
Closed

JIRA::HTTPError: JIRA::HTTPError #332

ankurjoshi54 opened this issue Apr 16, 2019 · 16 comments

Comments

@ankurjoshi54
Copy link

We have some scripts which we use for creating tasks in jira. But for couple of days i am getting following error

JIRA::HTTPError: JIRA::HTTPError
from /var/lib/gems/2.3.0/gems/jira-ruby-1.6.0/lib/jira/request_client.rb:15:in request' from /var/lib/gems/2.3.0/gems/jira-ruby-1.6.0/lib/jira/client.rb:238:in request'
from /var/lib/gems/2.3.0/gems/jira-ruby-1.6.0/lib/jira/client.rb:216:in get' from /var/lib/gems/2.3.0/gems/jira-ruby-1.6.0/lib/jira/base.rb:95:in all'
from /var/lib/gems/2.3.0/gems/jira-ruby-1.6.0/lib/jira/base_factory.rb:31:in block (2 levels) in delegate_to_target_class' from (irb):18 from /usr/bin/irb:11:in

'

Earlier i was using v1.4.3 but issue still persist after updating to v1.6.0.
I think it might be due to some changes in jira apis.
({
username: JiraAuth::USERNAME,
password: JiraAuth::PASSWORD,
site: JiraAuth::SITE,
context_path: '',
auth_type: :basic
} these are the parameters used for client.)

@simi
Copy link

simi commented Apr 18, 2019

I think it is probably caused by API changes - https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-user-privacy-api-migration-guide/#summary-of-changes.

I was able to get data with using accountId and passing cookie directly (stolen from my browser):

options = {
  :accountId     => 'UUID',
  :password     => 'password',
  :site         => 'URL',
  :context_path => '',
  :auth_type    => :basic,
  :use_cookies => true,
  :additional_cookies => ['cloud.session.token=myCookie']
}

I was able to get accountId from /people at our JIRA site.

@ankurjoshi54
Copy link
Author

Thanks for quick response. I will update the script to use this method for creating connection and will close the ticket on success.

@markj
Copy link

markj commented May 9, 2019

I had a similar problem but the issue is atlassian have started turning off the basic auth that we use. See https://ecosystem.atlassian.net/browse/ACJIRA-1466

Instead you need to generate a API token and use that as the account password (instead of the real password)

https://confluence.atlassian.com/cloud/api-tokens-938839638.html

@ankurjoshi54
Copy link
Author

Thanks, will try that. @simi's method sadly didn't work for me.

@robbyrussell
Copy link

Hi there,

I got the following email from Atlassian today. We use Jira Cloud

image

Am getting the same HTTPError response, too (in 1.6.0). I enabled the pry debugging in request_client.rb and it returns:

[1] pry(#<JIRA::HttpClient>)> response
=> #<Net::HTTPNotFound 404  readbody=true>

Here is the code that I'm testing with

jira_options = {
  username: 'USERNAME_HERE',
  password: 'API_KEY_HERE',
  site: 'https://planetargon.atlassian.net',
  auth_type: :basic,
}

jira_client = JIRA::Client.new(jira_options)
jira_client.Issue.find('PA-3700')

Any suggestions?

@robbyrussell
Copy link

Looks like it works once I switched from passing JIRA our username to our email address.

username: '[email protected]' works whereas username: 'robbyrussell' no longer worked

@serixscorpio
Copy link

I was able to confirm using api token instead of password worked. Thanks.
JIRA's deprecation notice

@martnst
Copy link

martnst commented Jun 18, 2019

✓ I can confirm too. It is working with replacing the password with API token.

However, for me another pitfall was, that following this guides you need to login with the hooked up user rather than your own user. So instead of [email protected] it is [email protected] in our case.

@JoeWoodward
Copy link

robbyrussell's change to use email + api_key works for me too!

@toomanyjoes
Copy link

I think the bigger issue here is the obfuscation of the real error. JIRA::HTTPError: JIRA::HTTPError should be JIRA::HTTPError: descriptive error message but because he's overriding StandardError's message attribute its printing the name of the error class twice. It's definitely a bug.

Something like this would fix it.

require 'forwardable'
module JIRA
  class HTTPError < StandardError
    extend Forwardable

    def_instance_delegators :@response, :code
    attr_reader :response, :my_message

    def initialize(response)
      @response = response
      @my_message = response.try(:message) || response.try(:body)
      super @my_message
    end
  end
end

@zephyrpathsofglory
Copy link

zephyrpathsofglory commented Oct 11, 2019

@toomanyjoes:
I think the main issue is that the response's message and body is empty, so @my_message is empty, I tried your method and return JIRA::HTTPError:, it hasn't improve anything.

@toomanyjoes
Copy link

toomanyjoes commented Oct 14, 2019

@zhangyonguu you're saying that JIRA's API doesn't return messages on its API error responses? I'd have to look into that but it seems hard to believe. Maybe it returns a custom error and the descriptive message isn't where you're expecting it to be? In any case returning JIRA::HTTPError: JIRA::HTTPError isn't helpful nor do I believe it's what is intended.

@grezar
Copy link

grezar commented May 23, 2020

Hmmm. I got nothing from such a terrible error message 🤦‍♂️

@zephyrpathsofglory
Copy link

JIRA::HTTPError.class_eval do
  def initialize(response)
    @response = response
    response_body = JSON.load(response.try(:body))
    @message = {
        message: response.try(:message),
        body: response_body.try(:[], "message") || response_body.try(:[], "errorMessage"),
        code: response.code,
        class: response.class.to_s,
        all: response_body
    }.to_json
    Raven.capture_message(@message)
  end
end

I capture the while messages when initializing the JIRA::HTTPError object and send it to my sentry server so that I can figure out the error details.

@zephyrpathsofglory
Copy link

zephyrpathsofglory commented Jun 3, 2020

@zhangyonguu you're saying that JIRA's API doesn't return messages on its API error responses? I'd have to look into that but it seems hard to believe. Maybe it returns a custom error and the descriptive message isn't where you're expecting it to be? In any case returning JIRA::HTTPError: JIRA::HTTPError isn't helpful nor do I believe it's what is intended.

JIRA::HTTPError.class_eval do
  def to_s
      @message
  end
end

this may help.

@bobbrodie
Copy link
Member

Hey everyone -- I know this message is old, but I've recently been doing some cleanup and preparing a new version. I believe there are two items here:

  1. API Tokens can be used as passwords
  2. The HTTPError does carry the message from Jira -- I've written about that here: Getting "undefined method presence for "Not Found":String" error when issue is not found #432 (comment)

An example would be requesting an issue that doesn't exist, where you'll receive an HTTPError as expected. If you inspect the HTTPError with something like this:

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

Then you'll see the original message:

{"errorMessages":["Issue does not exist or you do not have permission to see it."],"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