From 113e2fc7f37f2ac87a6802999903bb4321fed044 Mon Sep 17 00:00:00 2001 From: Mika Marttila Date: Fri, 8 Mar 2019 12:04:54 +0200 Subject: [PATCH] Adds feature flag for raise_on_response_errors --- lib/netsuite/configuration.rb | 9 +++++++ lib/netsuite/response.rb | 2 +- spec/netsuite/configuration_spec.rb | 1 - spec/netsuite/response_spec.rb | 41 ++++++++++++++++++----------- 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/lib/netsuite/configuration.rb b/lib/netsuite/configuration.rb index ac6e3aa88..e636b15fd 100644 --- a/lib/netsuite/configuration.rb +++ b/lib/netsuite/configuration.rb @@ -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 diff --git a/lib/netsuite/response.rb b/lib/netsuite/response.rb index b67c28e76..00496139d 100644 --- a/lib/netsuite/response.rb +++ b/lib/netsuite/response.rb @@ -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! diff --git a/spec/netsuite/configuration_spec.rb b/spec/netsuite/configuration_spec.rb index e3eaf7669..19bd8437d 100644 --- a/spec/netsuite/configuration_spec.rb +++ b/spec/netsuite/configuration_spec.rb @@ -370,5 +370,4 @@ expect(config.logger).to eql(logger) end end - end diff --git a/spec/netsuite/response_spec.rb b/spec/netsuite/response_spec.rb index ac0c96079..a429e63e6 100644 --- a/spec/netsuite/response_spec.rb +++ b/spec/netsuite/response_spec.rb @@ -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 @@ -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