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

WIP Handle unexpected errors #323

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
61 changes: 61 additions & 0 deletions spec/netsuite/utilities_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,67 @@

expect(NetSuite::Records::Account).to have_received(:get).exactly(1).times
end

it 'works when an unexpected error occurs' do
xml_msg = <<EOL
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<platformMsgs:documentInfo xmlns:platformMsgs="urn:messages_2015_1.platform.webservices.netsuite.com">
<platformMsgs:nsId>WEBSERVICES_TSTDRV1022750_103020151182829907744988579_5d1f6b</platformMsgs:nsId>
</platformMsgs:documentInfo>
</soapenv:Header>
<soapenv:Body>
<updateResponse xmlns="urn:messages_2015_1.platform.webservices.netsuite.com">
<writeResponse>
<platformCore:status xmlns:platformCore="urn:core_2015_1.platform.webservices.netsuite.com" isSuccess="false">
<platformCore:statusDetail type="ERROR">
<platformCore:code>UNEXPECTED_ERROR</platformCore:code>
<platformCore:message>An unexpected error occurred. Error ID: igduqcc81p7jpm8fklupr</platformCore:message>
</platformCore:statusDetail>
</platformCore:status>
<baseRef xmlns:platformCore="urn:core_2015_1.platform.webservices.netsuite.com" internalId="50534" type="revRecSchedule" xsi:type="platformCore:RecordRef"/>
</writeResponse>
</updateResponse>
</soapenv:Body>
</soapenv:Envelope>
EOL
xml_msg = <<EOL
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server.userException</faultcode>
<faultstring>An unexpected error occurred</faultstring>
<detail>
<ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">partners-java10006.bos.netledger.com</ns1:hostname>
</detail>
</soapenv:Fault>
</soapenv:Body>
EOL

# <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
# <soapenv:Body>
# <soapenv:Fault>
# <faultcode>soapenv:Server.userException</faultcode>
# <faultstring>You do not have permission to access web services feature.</faultstring>
# <detail>
# <platformFaults:UnexpectedErrorFault xmlns:platformFaults="urn:faults_2015_1.platform.webservices.netsuite.com">
# <platformFaults:code>UNEXPECTED_ERROR</platformFaults:code>
# <platformFaults:message>An unexpected error occurred. Error ID: j0b0mmf81qhk9h7ezjgbz</platformFaults:message>
# </platformFaults:UnexpectedErrorFault>
# <ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">partners-java10001.bos.netledger.com</ns1:hostname>
# </detail>
# </soapenv:Fault>
# </soapenv:Body>
# </soapenv:Envelope>

ns_account_id = 123

exception = Savon::SOAPFault.new(OpenStruct.new(body: xml_msg), Nori.new({}), xml_msg)

allow(NetSuite::Records::Account).to receive(:get).and_raise(exception)

NetSuite::Utilities.get_record(NetSuite::Records::Account, ns_account_id)
end
end

it 'pulls a record by internal id' do
Expand Down