diff --git a/app/models/print_job.rb b/app/models/print_job.rb index 42045e0b6..55afa7ea2 100644 --- a/app/models/print_job.rb +++ b/app/models/print_job.rb @@ -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 diff --git a/spec/models/print_job_spec.rb b/spec/models/print_job_spec.rb index 1c1d73021..2c19b40fc 100644 --- a/spec/models/print_job_spec.rb +++ b/spec/models/print_job_spec.rb @@ -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 @@ -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