class Puppet::Forge::Errors::ResponseError
This exception is raised when there is a bad HTTP response from the forge and optionally a message in the response.
Public Class Methods
new(options)
click to toggle source
@option options [String] :uri The URI that failed @option options [String] :input The user's input (e.g. module name) @option options [String] :message Error from the API response (optional) @option options [Puppet::HTTP::Response] :response The original HTTP response
Calls superclass method
Puppet::Error::new
# File lib/puppet/forge/errors.rb 79 def initialize(options) 80 @uri = options[:uri] 81 @message = options[:message] 82 response = options[:response] 83 @response = "#{response.code} #{response.reason.strip}" 84 85 begin 86 body = Puppet::Util::Json.load(response.body) 87 if body['message'] 88 @message ||= body['message'].strip 89 end 90 rescue Puppet::Util::Json::ParseError 91 end 92 93 message = if @message 94 _("Request to Puppet Forge failed.") + ' ' + _("Detail: %{detail}.") % { detail: "#{@message} / #{@response}" } 95 else 96 _("Request to Puppet Forge failed.") + ' ' + _("Detail: %{detail}.") % { detail: @response } 97 end 98 super(message, original) 99 end
Public Instance Methods
multiline()
click to toggle source
Return a multiline version of the error message
@return [String] the multiline version of the error message
# File lib/puppet/forge/errors.rb 104 def multiline 105 106 message = [] 107 message << _('Request to Puppet Forge failed.') 108 message << _(' The server being queried was %{uri}') % { uri: @uri } 109 message << _(" The HTTP response we received was '%{response}'") % { response: @response } 110 message << _(" The message we received said '%{message}'") % { message: @message } if @message 111 message.join("\n") 112 end