lib/acfs/errors.rb in acfs-1.4.0 vs lib/acfs/errors.rb in acfs-1.5.0

- old
+ new

@@ -24,11 +24,11 @@ end end class TimeoutError < RequestError def initialize(request) - super(request, "Timeout reached") + super(request, 'Timeout reached') end end # Response error containing the responsible response object. # @@ -36,17 +36,17 @@ attr_reader :response def initialize(opts = {}) @response = opts[:response] - if response - message = (opts[:message] ? opts[:message] + ':' : 'Received') + - " #{response.code} for #{response.request.method.upcase}" \ - " #{response.request.url} #{response.request.format}" - else - message = opts[:message] || 'Received erroneous response' - end + message = if response + (opts[:message] ? opts[:message] + ':' : 'Received') + + " #{response.code} for #{response.request.method.upcase}" \ + " #{response.request.url} #{response.request.format}" + else + opts[:message] || 'Received erroneous response' + end super opts, message end end @@ -65,15 +65,23 @@ super opts, message end end - # Resource not found error raised on a 404 response - # - class ResourceNotFound < ErroneousResponse - end + # 400 + class BadRequest < ErroneousResponse; end + # 401 + class Unauthorized < ErroneousResponse; end + + # 403 + class Forbidden < ErroneousResponse; end + + # 404 + class ResourceNotFound < ErroneousResponse; end + + # 422 class InvalidResource < ErroneousResponse attr_reader :errors, :resource def initialize(opts = {}) @errors = opts.delete :errors @@ -88,9 +96,21 @@ end super end end + + # 500 + class ServerError < ErroneousResponse; end + + # 502 + class BadGateway < ErroneousResponse; end + + # 503 + class ServiceUnavailable < ErroneousResponse; end + + # 504 + class GatewayTimeout < ErroneousResponse; end # A ResourceNotLoaded error will be thrown when calling some # modifing methods on not loaded resources as it is usally # unwanted to call e.g. `update_attributes` on a not loaded # resource.