This is the base class for all the services of the SDK. It contains the utility methods used by all of them.
Reads the response body and checks if it is an action or a fault. If it is an action it checks if the action contains a nested fault. If there is a fault then converts it to an `Error` and raises it. If there is no fault then the action object is returned.
This method is intended for internal use by other components of the SDK. Refrain from using it directly, as backwards compatibility isn't guaranteed.
@api private
# File lib/ovirtsdk4/service.rb, line 81 def check_action(response) body = response.body raise_error(response, nil) if body.nil? || body.length.zero? body = Reader.read(body) raise_error(response, body) if body.is_a?(Fault) if body.is_a?(Action) return body if body.fault.nil? raise_error(response, body.fault) end raise Error, "Expected an action or a fault, but got '#{body.class.name.split('::').last}'" end
Reads the response body, checks if it is a fault and if so converts it to an Error and raises it.
This method is intended for internal use by other components of the SDK. Refrain from using it directly, as backwards compatibility isn't guaranteed.
@api private
# File lib/ovirtsdk4/service.rb, line 63 def check_fault(response) body = response.body raise_error(response, nil) if body.nil? || body.length.zero? body = Reader.read(body) raise_error(response, body) if body.is_a?(Fault) raise Error, "Expected a fault, but got '#{body.class.name.split('::').last}'" end
Creates and raises an error containing the details of the given HTTP response and fault.
This method is intended for internal use by other components of the SDK. Refrain from using it directly, as backwards compatibility isn't guaranteed.
@api private
# File lib/ovirtsdk4/service.rb, line 30 def raise_error(response, fault) message = '' unless fault.nil? unless fault.reason.nil? message << ' ' unless message.empty? message << "Fault reason is \"#{fault.reason}\"." end unless fault.detail.nil? message << ' ' unless message.empty? message << "Fault detail is \"#{fault.detail}\"." end end unless response.nil? unless response.code.nil? message << ' ' unless message.empty? message << "HTTP response code is #{response.code}." end unless response.message.nil? message << ' ' unless message.empty? message << "HTTP response message is \"#{response.message}\"." end end raise Error, message end