diff --git a/lib/rock_rms/error.rb b/lib/rock_rms/error.rb index fd21921..01b8c31 100644 --- a/lib/rock_rms/error.rb +++ b/lib/rock_rms/error.rb @@ -41,10 +41,26 @@ def on_complete(env) when ERROR_STATUSES raise RockRMS::Error, error_message(env) end + + check_html_error(env) end private + def html_body?(body) + body.start_with?('') + end + + def check_html_error(env) + return unless html_body?(env[:body]) + + return unless /An error has occurred while processing your request/ =~ env[:body] + + raise RockRMS::InternalServerError, error_message( + status: 500, url: env[:url], body: 'Unknown API error.' + ) + end + def error_message(env) "#{env[:status]}: #{env[:url]} #{env[:body]}" end diff --git a/spec/rock_rms/error_spec.rb b/spec/rock_rms/error_spec.rb index cfcd774..31ca5ce 100644 --- a/spec/rock_rms/error_spec.rb +++ b/spec/rock_rms/error_spec.rb @@ -73,4 +73,12 @@ def expect_success end end end + + context 'html error responses' do + it 'raises exception for html error' do + body = File.read('spec/rock_rms/fixtures/html_error.html') + stub(200, body) + expect_failure(500, 'Unknown API error.') + end + end end diff --git a/spec/rock_rms/fixtures/html_error.html b/spec/rock_rms/fixtures/html_error.html new file mode 100644 index 0000000..fb2a1d3 --- /dev/null +++ b/spec/rock_rms/fixtures/html_error.html @@ -0,0 +1,107 @@ + + + +
+