Bug 1443420 - [RFE] Add a mechanism to check the HTTP result code of errors
Summary: [RFE] Add a mechanism to check the HTTP result code of errors
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: ovirt-engine-sdk-ruby
Classification: oVirt
Component: Core
Version: 4.1.5
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: ovirt-4.1.3
: 4.1.6
Assignee: Juan Hernández
QA Contact: Aleksei Slaikovskii
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-04-19 08:41 UTC by Juan Hernández
Modified: 2017-07-06 13:24 UTC (History)
5 users (show)

Fixed In Version: 4.1.6
Clone Of:
Environment:
Last Closed: 2017-07-06 13:24:59 UTC
oVirt Team: Infra
Embargoed:
rule-engine: ovirt-4.1+
lsvaty: testing_plan_complete-
mgoldboi: planning_ack+
juan.hernandez: devel_ack+
lsvaty: testing_ack+


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
oVirt gerrit 75665 0 master MERGED Add Error.code 2017-05-19 08:41:07 UTC
oVirt gerrit 77009 0 sdk_4.1 MERGED Add Error.code 2017-05-28 11:41:35 UTC

Description Juan Hernández 2017-04-19 08:41:27 UTC
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

Comment 1 Aleksei Slaikovskii 2017-06-19 08:48:48 UTC
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


Note You need to log in before you can comment on or make changes to this bug.