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

misc(netsuite): Process payload errors #2489

Merged
merged 1 commit into from
Aug 27, 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
6 changes: 4 additions & 2 deletions app/services/integrations/aggregator/base_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ def secret_key

def code(error)
json = error.json_message
json['type'].presence || json.dig('error', 'code')
json['type'].presence || json.dig('error', 'payload', 'name').presence || json.dig('error', 'code')
end

def message(error)
json = error.json_message
json.dig('payload', 'message').presence || json.dig('error', 'message')
json.dig('payload', 'message').presence ||
json.dig('error', 'payload', 'message').presence ||
json.dig('error', 'message')
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"error": {
"code": "action_script_runtime_error",
"payload": {
"name": "TypeError",
"message": "Please enter value(s) for: Company Name"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,41 @@
end
end

context 'when it is a server payload error' do
let(:error_code) { Faker::Number.between(from: 500, to: 599) }
let(:code) { 'TypeError' }
let(:message) { 'Please enter value(s) for: Company Name' }

let(:body) do
path = Rails.root.join('spec/fixtures/integration_aggregator/error_payload_response.json')
File.read(path)
end

it 'returns an error' do
result = service_call

aggregate_failures do
expect(result).not_to be_success
expect(result.error.code).to eq(code)
expect(result.error.message).to eq("#{code}: #{message}")
end
end

it 'delivers an error webhook' do
expect { service_call }.to enqueue_job(SendWebhookJob)
.with(
'customer.accounting_provider_error',
customer,
provider: 'netsuite',
provider_code: integration.code,
provider_error: {
message:,
error_code: code
}
)
end
end

context 'when it is a client error' do
let(:error_code) { 404 }
let(:code) { 'invalid_secret_key_format' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,41 @@
end
end

context 'when it is a server payload error' do
let(:error_code) { Faker::Number.between(from: 500, to: 599) }
let(:code) { 'TypeError' }
let(:message) { 'Please enter value(s) for: Company Name' }

let(:body) do
path = Rails.root.join('spec/fixtures/integration_aggregator/error_payload_response.json')
File.read(path)
end

it 'returns an error' do
result = service_call

aggregate_failures do
expect(result).not_to be_success
expect(result.error.code).to eq(code)
expect(result.error.message).to eq("#{code}: #{message}")
end
end

it 'delivers an error webhook' do
expect { service_call }.to enqueue_job(SendWebhookJob)
.with(
'customer.accounting_provider_error',
customer,
provider: 'netsuite',
provider_code: integration.code,
provider_error: {
message:,
error_code: code
}
)
end
end

context 'when it is a client error' do
let(:error_code) { 404 }
let(:code) { 'invalid_secret_key_format' }
Expand Down