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

Add element name to IntuitRequestException and message #609

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/quickbooks-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class MissingRealmError < Error; end
class UnsupportedOperation < Error; end

class IntuitRequestException < Error
attr_accessor :message, :code, :detail, :type, :intuit_tid, :request_xml, :request_json
attr_accessor :message, :code, :detail, :element, :type, :intuit_tid, :request_xml, :request_json

def initialize(msg)
self.message = msg
Expand Down
6 changes: 4 additions & 2 deletions lib/quickbooks/service/base_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,12 @@ def response_body_messages(response)

def parse_and_raise_exception(options = {})
err = parse_intuit_error
ex = Quickbooks::IntuitRequestException.new("#{err[:message]}:\n\t#{err[:detail]}")
element_msg = err[:element] ? "#{err[:element]}: " : ""
ex = Quickbooks::IntuitRequestException.new("#{element_msg}#{err[:message]}:\n\t#{err[:detail]}")
ex.code = err[:code]
ex.detail = err[:detail]
ex.type = err[:type]
ex.element = err[:element] if err[:element]
if is_json?
ex.request_json = options[:request]
else
Expand Down Expand Up @@ -448,7 +450,7 @@ def parse_intuit_error
end
element_attr = error_element.attributes['element']
if element_attr
error[:element] = code_attr.value
error[:element] = element_attr.try(:value)
dmorehouse marked this conversation as resolved.
Show resolved Hide resolved
end
error[:message] = error_element.xpath("//xmlns:Message").text
error[:detail] = error_element.xpath("//xmlns:Detail").text
Expand Down
8 changes: 8 additions & 0 deletions spec/fixtures/item_name_too_long_error.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2024-04-09T07:52:37.581-07:00">
<Fault type="ValidationFault">
<Error code="2050" element="Name">
<Message>String length is either shorter or longer than supported by specification</Message>
<Detail>String length specified does not match the supported length. Min:0 Max:100 supported. Supplied length:103</Detail>
</Error>
</Fault>
</IntuitResponse>
13 changes: 13 additions & 0 deletions spec/lib/quickbooks/service/base_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@
expect { @service.send(:check_response, response) }.to raise_error(Quickbooks::IntuitRequestException)
end

it "should parse all the error fields" do
xml = fixture('item_name_too_long_error.xml')
response = Struct.new(:code, :plain_body).new(400, xml)
expect { @service.send(:check_response, response, :request => xml) }.to raise_error { |error|
expect(error.type).to eq "ValidationFault"
expect(error.code).to eq "2050"
expect(error.element).to eq "Name"
expect(error.detail).to eq "String length specified does not match the supported length. Min:0 Max:100 supported. Supplied length:103"
expect(error.message).to include "String length is either shorter or longer than supported by specification"
expect(error.message).to include "String length specified does not match the supported length. Min:0 Max:100 supported. Supplied length:103"
}
end

it "should add request xml to request exception" do
xml = fixture('generic_error.xml')
xml2 = fixture('customer.xml')
Expand Down
Loading