diff --git a/lib/request_errors.rb b/lib/request_errors.rb index fc5a9e0..3e84e8a 100644 --- a/lib/request_errors.rb +++ b/lib/request_errors.rb @@ -30,6 +30,10 @@ module RestClient end end + class NotModified < Exception + ErrorMessage = 'NotModified' + end + # Authorization is required to access the resource specified. class Unauthorized < ExceptionWithResponse ErrorMessage = 'Unauthorized' diff --git a/lib/rest_client.rb b/lib/rest_client.rb index be45ffb..8b65f11 100644 --- a/lib/rest_client.rb +++ b/lib/rest_client.rb @@ -202,6 +202,8 @@ module RestClient end raise Redirect, url + elsif res.code == "304" + raise NotModified elsif res.code == "401" raise Unauthorized, res elsif res.code == "404" @@ -230,7 +232,7 @@ module RestClient end def response_log(res) - "# => #{res.code} #{res.class.to_s.gsub(/^Net::HTTP/, '')} | #{(res['Content-type'] || '').gsub(/;.*$/, '')} #{res.body.size} bytes" + "# => #{res.code} #{res.class.to_s.gsub(/^Net::HTTP/, '')} | #{(res['Content-type'] || '').gsub(/;.*$/, '')} #{(res.body) ? res.body.size : nil} bytes" end def display_log(msg)