From Juan Hernandez <juan.hernandez(a)redhat.com>:
Juan Hernandez has submitted this change and it was merged.
Change subject: Add Error.code
......................................................................
Add Error.code
This patch adds a new 'code' attribute to the Error class.
For errors that are HTTP related, this will contain the HTTP response
code. For example, if the method to retrieve a virtual machine fails
because it doesn't exist, this will contain the value 404. The users of
the SDK can use it like this:
# Get the identifier of the virtual machine from some place, maybe
# from a database that is out of sync with the engine:
id = ...
# Find the service that manages that virtual machine. Note that this
# will always succeed, even if the virtual machine doesn't exist, as
# the calls to the 'whatever_service' methods *do not* perform any
# call to the server.
vm_service = vms_service.vm_service(id)
# Try to retrieve the virtual machine. This *does* send the request
# to the server, hence it may fail if the virtual machine doesn't
# exist.
begin
vm = vm_service.get
rescue OvirtSDK4::Error => error
if error.code == 404
# The virtual machine doesn't exist, handle it.
...
else
# Something else happened that we don't know how to handle.
raise
end
end
For errors that aren't HTTP related, the value of the new attribute will
be 'nil'.
Change-Id: I6e3fc71e17fa1726049ca1e49c8cc9e295c15b0c
Bug-Url:
https://bugzilla.redhat.com/1443420
Signed-off-by: Juan Hernandez <juan.hernandez(a)redhat.com>
---
M sdk/lib/ovirtsdk4.rb
M sdk/lib/ovirtsdk4/connection.rb
A sdk/lib/ovirtsdk4/error.rb
M sdk/spec/vm_service_spec.rb
4 files changed, 47 insertions(+), 1 deletion(-)
Approvals:
Ondra Machacek: Looks good to me, but someone else must approve
Juan Hernandez: Verified; Looks good to me, approved
Jenkins CI: Passed CI tests
--
To view, visit
https://gerrit.ovirt.org/75665
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6e3fc71e17fa1726049ca1e49c8cc9e295c15b0c
Gerrit-PatchSet: 5
Gerrit-Project: ovirt-engine-sdk-ruby
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <juan.hernandez(a)redhat.com>
Gerrit-Reviewer: Boris Odnopozov <bodnopoz(a)redhat.com>
Gerrit-Reviewer: Jenkins CI
Gerrit-Reviewer: Juan Hernandez <juan.hernandez(a)redhat.com>
Gerrit-Reviewer: Ondra Machacek <omachace(a)redhat.com>
Gerrit-Reviewer: gerrit-hooks <automation(a)ovirt.org>