Skip to content
Open
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
18 changes: 15 additions & 3 deletions lib/netsuite/actions/initialize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ def action_name
:initialize
end

def response_errors
if response_hash[:status] && response_hash[:status][:status_detail]
@response_errors ||= errors
end
end

def errors
error_obj = response_hash[:status][:status_detail]
error_obj = [error_obj] if error_obj.instance_of?(Hash)
error_obj.map do |error|
NetSuite::Error.new(error)
end
end

module Support

def self.included(base)
Expand All @@ -74,13 +88,11 @@ def initialize(object, credentials={})
if response.success?
new(response.body)
else
raise InitializationError, "#{self}.initialize with #{object} failed."
raise InitializationError, response.errors.find { |e| e.type == 'ERROR' }.message
end
end

end
end

end
end
end
2 changes: 1 addition & 1 deletion lib/netsuite/records/journal_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class JournalEntry
include Support::Actions
include Namespaces::TranGeneral

actions :get, :get_list, :add, :delete, :search, :upsert, :upsertlist
actions :get, :get_list, :add, :delete, :search, :upsert, :upsert_list

fields :approved, :created_date, :exchange_rate, :last_modified_date, :memo, :reversal_date, :reversal_defer, :reversal_entry,
:tran_date, :tran_id
Expand Down
8 changes: 5 additions & 3 deletions spec/netsuite/records/vendor_bill_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,16 @@
end

context 'when the response is unsuccessful' do
let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
let(:error1) { NetSuite::Error.new(:@type => 'ERROR', :message => 'You can not initialize vendorbill: invalid reference.') }
let(:error2) { NetSuite::Error.new(:@type => 'ERROR', :message => 'some message') }
let(:response) { NetSuite::Response.new(:success => false, :body => {}, :errors => [error1, error2]) }

it 'raises a InitializationError exception' do
it 'raises a InitializationError exception capturing the message of the first error in the response object' do
expect(NetSuite::Actions::Initialize).to receive(:call).with([NetSuite::Records::VendorBill, vendor], {}).and_return(response)
expect {
NetSuite::Records::VendorBill.initialize(vendor)
}.to raise_error(NetSuite::InitializationError,
/NetSuite::Records::VendorBill.initialize with .+ failed./)
/You can not initialize vendorbill: invalid reference/)
end
end
end
Expand Down
8 changes: 5 additions & 3 deletions spec/netsuite/records/vendor_payment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,16 @@
end

context 'when the response is unsuccessful' do
let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
let(:error1) { NetSuite::Error.new(:@type => 'ERROR', :message => 'You can not initialize vendorpayment: invalid reference.') }
let(:error2) { NetSuite::Error.new(:@type => 'ERROR', :message => 'some message') }
let(:response) { NetSuite::Response.new(:success => false, :body => {}, :errors => [error1, error2]) }

it 'raises a InitializationError exception' do
it 'raises a InitializationError exception capturing the message of the first error in the response object' do
expect(NetSuite::Actions::Initialize).to receive(:call).with([NetSuite::Records::VendorPayment, vendor], {}).and_return(response)
expect {
NetSuite::Records::VendorPayment.initialize(vendor)
}.to raise_error(NetSuite::InitializationError,
/NetSuite::Records::VendorPayment.initialize with .+ failed./)
/You can not initialize vendorpayment: invalid reference/)
end
end
end
Expand Down