Skip to content

Commit

Permalink
Adds feature flag for raise_on_response_errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aom committed Mar 8, 2019
1 parent 77d34a2 commit 113e2fc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
9 changes: 9 additions & 0 deletions lib/netsuite/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,5 +364,14 @@ def log_level(value = nil)
def log_level=(value)
attributes[:log_level] ||= value
end

def raise_on_response_errors(value = nil)
self.raise_on_response_errors = value || false
attributes[:raise_on_response_errors]
end

def raise_on_response_errors=(value)
attributes[:raise_on_response_errors] ||= value
end
end
end
2 changes: 1 addition & 1 deletion lib/netsuite/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(attributes = {})
@body = attributes[:body]
@errors = attributes[:errors] || []

raise_on_response_errors!
raise_on_response_errors! if NetSuite::Configuration.raise_on_response_errors
end

def success!
Expand Down
1 change: 0 additions & 1 deletion spec/netsuite/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,5 +370,4 @@
expect(config.logger).to eql(logger)
end
end

end
41 changes: 26 additions & 15 deletions spec/netsuite/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

describe NetSuite::Response do
let(:response) { NetSuite::Response.new }
let(:insufficient_permission_response) {
NetSuite::Response.new(
:success => false,
:body => {
status: {
status_detail: {
:@type => 'ERROR',
:code => 'INSUFFICIENT_PERMISSION',
:message => 'Permission Violation: The subsidiary restrictions on your role prevent you from seeing this record.'
}
}
}
)
}

describe '#initialize' do
it 'allows the body to be set through a :body option' do
Expand All @@ -15,21 +29,18 @@
expect(response).to be_success
end

it 'throws PermissionError when response failed to INSUFFICIENT_PERMISSION' do
expect {
NetSuite::Response.new(
:success => false,
:body => {
status: {
status_detail: {
:@type => 'ERROR',
:code => 'INSUFFICIENT_PERMISSION',
:message => 'Permission Violation: The subsidiary restrictions on your role prevent you from seeing this record.'
}
}
}
)
}.to raise_error(NetSuite::PermissionError)
it 'fails silently when response failed' do
expect { insufficient_permission_response }.not_to raise_error
end

context 'with raise_on_response_errors' do
it 'throws PermissionError when response failed to INSUFFICIENT_PERMISSION' do
NetSuite.configure do
raise_on_response_errors true
end

expect { insufficient_permission_response }.to raise_error(NetSuite::PermissionError)
end
end
end

Expand Down

0 comments on commit 113e2fc

Please sign in to comment.