diff --git a/lib/lgtm/error_handleable.rb b/lib/lgtm/error_handleable.rb index dfac39a..ab6810a 100644 --- a/lib/lgtm/error_handleable.rb +++ b/lib/lgtm/error_handleable.rb @@ -1,21 +1,22 @@ module Lgtm + # ErrorHandleable of module of error handling module ErrorHandleable - # 2xx http success status. - SUCCESS_STATUSES = [Net::HTTPSuccess, Net::HTTPFound] # 4xx http status. - CLIENT_ERRORS = [Net::HTTPBadRequest, Net::HTTPForbidden, Net::HTTPNotFound] + CLIENT_ERRORS = [ + Net::HTTPBadRequest, + Net::HTTPForbidden, + Net::HTTPNotFound + ].freeze # 5xx http status. SERVER_ERRORS = [ Net::HTTPInternalServerError, Net::HTTPBadGateway, Net::HTTPServiceUnavailable, - Net::HTTPGatewayTimeOut, - ] + Net::HTTPGatewayTimeOut + ].freeze def validate_response(response) case response - when *SUCCESS_STATUSES - # Nothing to do. when *SERVER_ERRORS raise ::Lgtm::Errors::UnexpectedError when *CLIENT_ERRORS diff --git a/lib/lgtm/plugin.rb b/lib/lgtm/plugin.rb index f425510..0c074bc 100644 --- a/lib/lgtm/plugin.rb +++ b/lib/lgtm/plugin.rb @@ -55,8 +55,7 @@ def fetch_image_url(https_image_only: false) return fetch_image_url(https_image_only: true) end url - rescue ::Lgtm::Errors::UnexpectedError - nil + rescue ::Lgtm::Errors::UnexpectedError; nil end def process_request(url) diff --git a/spec/lgtm_spec.rb b/spec/lgtm_spec.rb index 239a0d9..04f4369 100644 --- a/spec/lgtm_spec.rb +++ b/spec/lgtm_spec.rb @@ -18,7 +18,12 @@ def mock(request_url: 'https://lgtm.in/p/sSuI4hm0q', end describe '#check_lgtm' do - subject { lgtm.check_lgtm(https_image_only: https_image_only, image_url: image_url) } + subject do + lgtm.check_lgtm( + https_image_only: https_image_only, + image_url: image_url + ) + end let(:dangerfile) { testing_dangerfile } let(:lgtm) { dangerfile.lgtm } @@ -42,7 +47,8 @@ def mock(request_url: 'https://lgtm.in/p/sSuI4hm0q', end it 'lgtm with errors' do - allow(lgtm).to receive(:validate_response).and_raise(::Lgtm::Errors::UnexpectedError) + allow(lgtm).to receive(:validate_response) + .and_raise(::Lgtm::Errors::UnexpectedError) is_expected expect(dangerfile.status_report[:markdowns][0].message) .to eq("