sumoheavy / jira-ruby

A Ruby gem for the JIRA REST API
MIT License
657 stars 411 forks source link

JIRA::HTTPError: Not Found - /jira/request_client.rb:13:in request' #399

Open Sachin796 opened 1 year ago

Sachin796 commented 1 year ago

Help to resolve JIRA::HTTPError: Not Found error while executing a ruby file from policies file.

Behaviour

Approach


# frozen_string_literal: true

require 'jira-ruby'
require 'json'

module Test
  module Jira
    # Connection to JIRA API.
    class Connection
      API_TOKEN = ENV.fetch('JIRA_USER_TOKEN', nil)
      attr_reader :client

      def initialize
        @params = {
          site:            'https://jira.xxx.xx:443',
          context_path:    '',
          username:        ENV.fetch('JIRA_USERNAME', nil),
          password:        ENV.fetch('JIRA_USER_TOKEN', nil),
          auth_type:       :basic,
          use_ssl:          true,
          ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE
        }
        @client = JIRA::Client.new(@params)
      end

      def find_project()
        client.Project.find((ENV.fetch('JIRA_PROJECT_ID', nil)))
      rescue JIRA::HTTPError => e
        puts 'Error while finding project'
        puts e.response.code
        puts e.response.message
      end
    end
  end
end

$ ruby test.rb For a better Pry experience on Windows, please use ansicon: https://github.com/adoxa/ansicon If you use an alternative to ansicon and dont want to see this warning again, you can add "Pry.config.windows_console_warning = false" to your pryrc.

C:/Users/User_Name/Documents/test.rb:343 :

338:   use_ssl: true,
339:   ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE
340: }
341:
342: client = JIRA::Client.new(options)

=> 343: binding.pry

[1] pry(main)> client.Project.find('<>') => #<JIRA::Resource::Project:0x000002bc4356f660 @attrs= {"key"=>"<>", "expand"=>"description,lead,url,projectKeys", "self"=>"https://jira.xxx.xxx.xx/rest/api/2/project/<>", "id"=>"<>", "description"=>"", "lead"=>



- When I try to execute the same snippet of code but using the policies file... it gives me the following error.

`
[4] pry(#<Test::Jira::Connection>)> client.Project.find('<<id>>') JIRA::HTTPError: Not Found from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/jira-ruby-2.2.0/lib/jira/request_client.rb:13:in request'`
`
- I am currently uncertain of why the issue is present only when I run the code using a `policies` file and not the standalone `.rb` file.

- I have all the `env`and `proxies` setup, and I can get the data using the API call using Postman.

![image](https://user-images.githubusercontent.com/11441603/213566313-739c967b-9119-401e-9c8b-86030982db61.png)

- STRUCTURE OF THE POLICIES FILE

![image](https://user-images.githubusercontent.com/11441603/213730085-cdffb04d-77c8-4485-8e74-74e0d4b54443.png)

Any help would be great!

Thank you.
Sachin796 commented 1 year ago

Hi, Can anyone let me know if they can help out with the bug that I am facing if they have experienced the same.

Thanks.

Sachin796 commented 1 year ago

Hi, Can anyone let me know if they can help out with the bug.

Thanks.