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

- old
+ new

@@ -6,10 +6,11 @@ # Describes a CRUD operation. Handle request creation and response # processing as well as error handling and stubbing. # class Operation attr_reader :action, :params, :resource, :data, :callback, :location, :url + delegate :service, to: :resource delegate :call, to: :callback def initialize(resource, action, opts = {}, &block) @resource = resource @@ -69,13 +70,27 @@ request end def handle_failure(response) case response.code + when 400 + raise ::Acfs::BadRequest.new response: response + when 401 + raise ::Acfs::Unauthorized.new response: response + when 403 + raise ::Acfs::Forbidden.new response: response when 404 raise ::Acfs::ResourceNotFound.new response: response when 422 raise ::Acfs::InvalidResource.new response: response, errors: response.data.try(:[], 'errors') + when 500 + raise ::Acfs::ServerError.new response: response + when 502 + raise ::Acfs::BadGateway.new response: response + when 503 + raise ::Acfs::ServiceUnavailable.new response: response + when 504 + raise ::Acfs::GatewayTimeout.new response: response else raise ::Acfs::ErroneousResponse.new response: response end end end