lib/conjur/cli.rb in conjur-cli-4.19.0 vs lib/conjur/cli.rb in conjur-cli-4.20.1

- old
+ new

@@ -1,7 +1,7 @@ # -# Copyright (C) 2013 Conjur Inc +# Copyright (C) 2013-2015 Conjur Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy of # this software and associated documentation files (the "Software"), to deal in # the Software without restriction, including without limitation the rights to # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of @@ -119,21 +119,22 @@ true end on_error do |exception| require 'rest-client' - if exception.is_a?(RestClient::Exception) - begin - body = JSON.parse(exception.response.body) - $stderr.puts body['error'] - rescue - $stderr.puts exception.response.body if exception.response + require 'patches/conjur/error' + + run_default_handler = true + if exception.is_a?(RestClient::Exception) && exception.response + err = Conjur::Error.create exception.response.body + if err + $stderr.puts "error: " + err.message + run_default_handler = false # suppress default error message + else + $stderr.puts exception.response.body end end - require 'conjur/log' - if Conjur.log - Conjur.log << "error: #{exception}\n#{exception.backtrace.join("\n") rescue 'NO BACKTRACE?'}" - end - true + + run_default_handler end end end