deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michal Fojtik <mfoj...@redhat.com>
Subject Re: [PATCH] Fixed processing of error responses
Date Wed, 27 Feb 2013 14:56:01 GMT
On 02/27, jprovazn@redhat.com wrote:

ACK. Pushing.

> From: Jan Provaznik <jprovazn@redhat.com>
> 
> Error responses from server don't have to contain backend node, only a message.
> For example 401 error response looks like:
> <error status='401' url='/api/instances'>
>   <message>Authentication required</message>
> </error>
> 
> This patch makes sure that dc-client doesn't fail if 'backend' node is not present.
> ---
>  client/lib/deltacloud.rb | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
> index c3efcde..a58c280 100644
> --- a/client/lib/deltacloud.rb
> +++ b/client/lib/deltacloud.rb
> @@ -366,10 +366,12 @@ module DeltaCloud
>          DeltaCloud::HTTPError.client_error(response.code)
>        else
>          opts = {
> -          :driver => (xml/'backend').first[:driver],
> -          :provider => (xml/'backend').first[:provider],
>            :params => (xml/'request/param').inject({}) { |r,p| r[:"#{p[:name]}"] =
p.text; r }
>          }
> +        if backend_node = xml.at_xpath('/error/backend')
> +          opts[:driver]   = backend_node[:driver]
> +          opts[:provider] = backend_node[:provider]
> +        end
>          backtrace = (xml/'backtrace').empty? ? nil : (xml/'backtrace').first.text.split("\n")[1..10].map
{ |l| l.strip }
>          DeltaCloud::HTTPError.server_error(xml.root[:status] || response.code,
>                                             (xml/'message').first.text, opts, backtrace)
> -- 
> 1.7.11.7
> 

-- 
Michal Fojtik <mfojtik@redhat.com>
Deltacloud API, CloudForms

Mime
View raw message