lib/acfs/errors.rb in acfs-0.42.0 vs lib/acfs/errors.rb in acfs-0.43.0
- old
+ new
@@ -1,16 +1,17 @@
module Acfs
-
# Acfs base error.
#
class Error < StandardError
def initialize(opts = {}, message = nil)
opts.merge! message: message if message
super opts[:message]
end
end
+ class UnsupportedOperation < StandardError; end
+
# Response error containing the responsible response object.
#
class ErroneousResponse < Error
attr_reader :response
@@ -19,24 +20,24 @@
message = opts[:message] || 'Received erroneous response'
if response
message << ": #{response.code}"
if response.data
message << "\n with content:\n "
- message << response.data.map{|k,v| "#{k.inspect}: #{v.inspect}"}.join("\n ")
+ message << response.data.map {|k, v| "#{k.inspect}: #{v.inspect}" }.join("\n ")
end
if response.headers.any?
message << "\n with headers:\n "
- message << response.headers.map{|k,v| "#{k}: #{v}"}.join("\n ")
+ message << response.headers.map {|k, v| "#{k}: #{v}" }.join("\n ")
end
message << "\nbased on request: #{response.request.method.upcase} #{response.request.url} #{response.request.format}"
if response.request.data
message << "\n with content:\n "
- message << response.request.data.map{|k,v| "#{k.inspect}: #{v.inspect}"}.join("\n ")
+ message << response.request.data.map {|k, v| "#{k.inspect}: #{v.inspect}" }.join("\n ")
end
if response.request.headers.any?
message << "\n with headers:\n "
- message << response.request.headers.map{|k,v| "#{k}: #{v}"}.join("\n ")
+ message << response.request.headers.map {|k, v| "#{k}: #{v}" }.join("\n ")
end
end
super opts, message
end
end
@@ -48,24 +49,24 @@
@stubs = opts.delete :stubs
@operation = opts.delete :operation
super opts, 'Ambiguous stubs.'
end
-
end
# Resource not found error raised on a 404 response
#
class ResourceNotFound < ErroneousResponse
end
+ #
class InvalidResource < ErroneousResponse
attr_reader :errors, :resource
def initialize(opts = {})
@errors = opts.delete :errors
@resource = opts.delete :resource
- opts[:message] ||= @errors.map{ |k,v| "#{k}: #{v.join ', '}" }.join ', ' if @errors.is_a? Hash
+ opts[:message] ||= @errors.map {|k, v| "#{k}: #{v.join ', '}" }.join ', ' if @errors.is_a? Hash
opts[:message] ||= @errors.join ', ' if @errors.is_a? Array
super
end
end