Skip to content

Commit

Permalink
Merge pull request #28 from IBM/send-trans-id
Browse files Browse the repository at this point in the history
fix: check for transaction id in error response
  • Loading branch information
mamoonraja authored Jan 29, 2020
2 parents a7c8056 + 32691a7 commit 625a95e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/ibm_cloud_sdk_core/api_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions test/unit/test_base_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -180,7 +180,7 @@ def test_dummy_request_form_data
method: "POST",
form: form_data,
headers: { "Accept" => "application/json" },
url: ""
url: "dummy/endpoint"
)
end

Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit 625a95e

Please sign in to comment.