From 335b63d75724bb24c1021145aee2ff222bae526b Mon Sep 17 00:00:00 2001 From: Alexander Olofsson <alexander.olofsson@liu.se> Date: Tue, 19 Oct 2021 16:57:42 +0200 Subject: [PATCH] Fix error message handling for newer Passwordstate --- lib/passwordstate.rb | 2 +- lib/passwordstate/client.rb | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/passwordstate.rb b/lib/passwordstate.rb index b0ce6d9..49a57d1 100644 --- a/lib/passwordstate.rb +++ b/lib/passwordstate.rb @@ -1,10 +1,10 @@ require 'logging' +require 'passwordstate/version' require 'passwordstate/client' require 'passwordstate/errors' require 'passwordstate/resource' require 'passwordstate/resource_list' require 'passwordstate/util' -require 'passwordstate/version' module Passwordstate def self.debug! diff --git a/lib/passwordstate/client.rb b/lib/passwordstate/client.rb index 9444ecf..c95f665 100644 --- a/lib/passwordstate/client.rb +++ b/lib/passwordstate/client.rb @@ -108,10 +108,11 @@ module Passwordstate if data return data if res_obj.is_a? Net::HTTPSuccess - data = data&.first - data = data.fetch('errors', []) if data.is_a? Hash + parsed = data&.first + parsed = data.fetch('errors', []) if data.is_a?(Hash) && data.key?('errors') + parsed = [data] - raise Passwordstate::HTTPError.new_by_code(res_obj.code, req_obj, res_obj, data || []) + raise Passwordstate::HTTPError.new_by_code(res_obj.code, req_obj, res_obj, parsed || []) else return res_obj.body if res_obj.is_a?(Net::HTTPSuccess) && options.fetch(:allow_html, true) -- GitLab