diff --git a/lib/ibm_cloud_sdk_core/api_exception.rb b/lib/ibm_cloud_sdk_core/api_exception.rb index c531da9..f50f534 100644 --- a/lib/ibm_cloud_sdk_core/api_exception.rb +++ b/lib/ibm_cloud_sdk_core/api_exception.rb @@ -26,8 +26,8 @@ def initialize(code: nil, error: nil, info: nil, transaction_id: nil, global_tra @info = info # :nocov: end - @transaction_id = transaction_id - @global_transaction_id = global_transaction_id + @transaction_id = transaction_id || response.headers["X-Dp-Watson-Tran-Id"] + @global_transaction_id = global_transaction_id || response.headers["X-Global-Transaction-Id"] end def to_s diff --git a/test/unit/test_base_service.rb b/test/unit/test_base_service.rb index aeb6fa1..484c5dc 100644 --- a/test/unit/test_base_service.rb +++ b/test/unit/test_base_service.rb @@ -163,15 +163,15 @@ def test_dummy_request_form_data authenticator = IBMCloudSdkCore::BearerTokenAuthenticator.new(bearer_token: "token") service = IBMCloudSdkCore::BaseService.new( service_name: "assistant", - authenticator: authenticator, - service_url: "https://gateway.watsonplatform.net/" + authenticator: authenticator ) + service.service_url = "https://gateway.watsonplatform.net/assistant/api/" form_data = {} file = File.open(Dir.getwd + "/resources/cnc_test.pdf") filename = file.path if filename.nil? && file.respond_to?(:path) form_data[:file] = HTTP::FormData::File.new(file, content_type: "application/octet-stream", filename: filename) - stub_request(:post, "https://gateway.watsonplatform.net/").with do |req| + stub_request(:post, "https://gateway.watsonplatform.net/assistant/api/dummy/endpoint").with do |req| # Test the headers. assert_equal(req.headers["Accept"], "application/json") assert_match(%r{\Amultipart/form-data}, req.headers["Content-Type"]) @@ -180,7 +180,7 @@ def test_dummy_request_form_data method: "POST", form: form_data, headers: { "Accept" => "application/json" }, - url: "" + url: "dummy/endpoint" ) end @@ -217,7 +217,8 @@ def test_dummy_request_icp stub_request(:get, "https://we.the.best/music") .with( headers: { - "Host" => "we.the.best" + "Host" => "we.the.best", + "Authorization" => "Basic YXBpa2V5OmljcC14eXo=" } ).to_return(status: 200, body: response.to_json, headers: headers) authenticator = IBMCloudSdkCore::BasicAuthenticator.new( @@ -226,9 +227,9 @@ def test_dummy_request_icp ) service = IBMCloudSdkCore::BaseService.new( service_name: "assistant", - authenticator: authenticator, - service_url: "https://we.the.best" + authenticator: authenticator ) + service.service_url = "https://we.the.best" service_response = service.request(method: "GET", url: "/music", headers: {}) assert_equal(response, service_response.result) end