Skip to content

Commit

Permalink
Adding better error names
Browse files Browse the repository at this point in the history
  • Loading branch information
dasunpubudumal committed Jan 21, 2025
1 parent 31b6bb7 commit 3d7f4eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion app/models/print_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,14 @@ def extract_error_message(response)
if response.body.present?
begin
response_body = JSON.parse(response.body)
return response_body['errors'].pluck('message').join(' - ') if response_body['errors'].present?
if response_body['errors'].present?
messages =
response_body['errors'].map do |error|
extension = error['extensions'] ? " (#{error['extensions']['classification']})" : ''
"#{error['message']}#{extension}"
end
return messages.join(' - ')
end
rescue JSON::ParserError
return 'Failed to parse JSON response from SprintClient'
end
Expand Down
6 changes: 4 additions & 2 deletions spec/models/print_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
allow(SPrintClient).to receive(:send_print_request).and_return(response)
expect(pj.execute).to be false
expect(pj.errors.full_messages[0]).to eq(
"Sprint Variable 'printRequest' has an invalid value: Expected type 'Int' but was 'Double'."
"Sprint Variable 'printRequest' has an invalid value: Expected type 'Int' but was 'Double'. (ValidationError)"
)
end

Expand All @@ -278,7 +278,9 @@
)
allow(SPrintClient).to receive(:send_print_request).and_return(response)
expect(pj.execute).to be false
expect(pj.errors.full_messages[0]).to eq('Sprint Failed to parse JSON response from SprintClient')
expect(pj.errors.full_messages[0]).to eq(
'Sprint Failed to parse JSON response from SprintClient (ValidationError)'
)
end
end
end

0 comments on commit 3d7f4eb

Please sign in to comment.