Commit a28f0fb8e6c6a4a6ce7a21c4c56b2c164256c695

Authored by Stephen Crosby
2 parents aa2e8315 1cc587c0
Exists in master and in 1 other branch production

Merge pull request #948 from stevecrozz/934_error_on_invalid_xml

refs #934 catch and provide error on invalid xml
app/controllers/notices_controller.rb
... ... @@ -24,6 +24,8 @@ class NoticesController < ApplicationController
24 24 else
25 25 render :text => "Your API key is unknown", :status => 422
26 26 end
  27 + rescue Nokogiri::XML::SyntaxError
  28 + render :text => 'The provided XML was not well-formed', :status => 422
27 29 end
28 30  
29 31 # Redirects a notice to the problem page. Useful when using User Information at Airbrake gem.
... ...
spec/controllers/notices_controller_spec.rb
... ... @@ -7,6 +7,15 @@ describe NoticesController, type: 'controller' do
7 7 let(:error_report) { double(:valid? => true, :generate_notice! => true, :notice => notice, :should_keep? => true) }
8 8  
9 9 context 'notices API' do
  10 + context "with bogus xml" do
  11 + it "returns an error" do
  12 + expect(request).to receive(:raw_post).and_return('<r><b>notxml</r>')
  13 + post :create, :format => :xml
  14 + expect(response.status).to eq(422)
  15 + expect(response.body).to eq('The provided XML was not well-formed')
  16 + end
  17 + end
  18 +
10 19 context "with all params" do
11 20 before do
12 21 expect(ErrorReport).to receive(:new).with(xml).and_return(error_report)
... ...