Currently when the SDK raises an exception to indicate an unexpected HTTP result code the details are embedded in the error message. For example, when trying to retrieve a VM that doesn't exist the SDK generates the following error message: HTTP response code is 404. But there isn't a simple way to extract that code, there is no `code` method in the OvirtSDK4::Error class. This means that the application that uses the SDK doesn't have a simple way to handle differently different kinds of errors. This should be improved, adding a `code` method to the Error class: begin ... rescue OvirtSDK4::Error => e if e.code == 404 ... else raise end end
Verified on rubygem-ovirt-engine-sdk4-4.1.6-1.el7ev.x86_64 $ cat 1443420.rb require 'logger' require 'ovirtsdk4' connection = OvirtSDK4::Connection.new( url: 'https://engine/ovirt-engine/api', username: 'admin@internal', password: '123456', ca_file: 'ca.crt', debug: true, log: Logger.new('example.log') ) begin vms_service = connection.system_service.vms_service vm_service = vms_service.vm_service('123') vm_service.get rescue OvirtSDK4::Error => e if e.code == 404 puts 'Got 404' else raise end end connection.close $ ruby 1443420.rb Got 404