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 78 def initialize(options) 79 @uri = options[:uri] 80 @message = options[:message] 81 response = options[:response] 82 @response = "#{response.code} #{response.reason.strip}" 83 84 begin 85 body = Puppet::Util::Json.load(response.body) 86 if body['message'] 87 @message ||= body['message'].strip 88 end 89 rescue Puppet::Util::Json::ParseError 90 end 91 92 message = if @message 93 _("Request to Puppet Forge failed.") + ' ' + _("Detail: %{detail}.") % { detail: "#{@message} / #{@response}" } 94 else 95 _("Request to Puppet Forge failed.") + ' ' + _("Detail: %{detail}.") % { detail: @response } 96 end 97 super(message, original) 98 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 103 def multiline 104 105 message = [] 106 message << _('Request to Puppet Forge failed.') 107 message << _(' The server being queried was %{uri}') % { uri: @uri } 108 message << _(" The HTTP response we received was '%{response}'") % { response: @response } 109 message << _(" The message we received said '%{message}'") % { message: @message } if @message 110 message.join("\n") 111 end