Exception: Rightscale::GogridError
- Defined in:
- lib/gogrid_base.rb
Overview
Exception class to signal any GoGrid errors. All errors occuring during calls to GoGrid’s web services raise this type of error. Attribute inherited by RuntimeError:
- the text of the error
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
either an array of errors where each item is itself an array of [code, message]), or an error string if the error was raised manually, as in
GogridError.new('err_text'). -
#http_code ⇒ Object
readonly
Response HTTP error code.
Class Method Summary collapse
-
.on_gogrid_exception(gogrid, options = {:raise=>true, :log=>true}) ⇒ Object
Generic handler for GogridErrors.
-
.system_error?(e) ⇒ Boolean
True if e is an system error, i.e.
Instance Method Summary collapse
-
#include?(pattern) ⇒ Boolean
Does any of the error messages include the regexp
pattern? Used to determine whether to retry request. -
#initialize(errors = nil, http_code = nil) ⇒ GogridError
constructor
A new instance of GogridError.
Constructor Details
#initialize(errors = nil, http_code = nil) ⇒ GogridError
Returns a new instance of GogridError.
321 322 323 324 325 |
# File 'lib/gogrid_base.rb', line 321 def initialize(errors=nil, http_code=nil) @errors = errors @http_code = http_code super(@errors.is_a?(Array) ? @errors.map{|code, msg| "#{code}: #{msg}"}.join("; ") : @errors.to_s) end |
Instance Attribute Details
#errors ⇒ Object (readonly)
either an array of errors where each item is itself an array of [code, message]), or an error string if the error was raised manually, as in GogridError.new('err_text')
316 317 318 |
# File 'lib/gogrid_base.rb', line 316 def errors @errors end |
#http_code ⇒ Object (readonly)
Response HTTP error code
319 320 321 |
# File 'lib/gogrid_base.rb', line 319 def http_code @http_code end |
Class Method Details
.on_gogrid_exception(gogrid, options = {:raise=>true, :log=>true}) ⇒ Object
Generic handler for GogridErrors. object that caused the exception (it must provide last_request and last_response). Supported boolean options are:
-
:logprint a message into the log using gogrid.logger to access the Logger -
:putsdo a “puts” of the error -
:raisere-raise the error after logging
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/gogrid_base.rb', line 344 def self.on_gogrid_exception(gogrid, ={:raise=>true, :log=>true}) # Only log & notify if not user error if ![:raise] || system_error?($!) error_text = "#{$!.inspect}\n#{$@}.join('\n')}" puts error_text if [:puts] # Log the error if [:log] request = gogrid.last_request ? gogrid.last_request.path : '-none-' response = gogrid.last_response ? "#{gogrid.last_response.code} -- #{gogrid.last_response.message} -- #{gogrid.last_response.body}" : '-none-' gogrid.logger.error error_text gogrid.logger.error "Request was: #{request}" gogrid.logger.error "Response was: #{response}" end end raise if [:raise] # re-raise an exception return nil end |
.system_error?(e) ⇒ Boolean
True if e is an system error, i.e. something that is for sure not the caller’s fault. Used to force logging. TODO: Place Gogrid Errors here (present ones are AWS errors)
365 366 367 |
# File 'lib/gogrid_base.rb', line 365 def self.system_error?(e) !e.is_a?(self) || e. =~ /InternalError|InsufficientInstanceCapacity|Unavailable/ end |
Instance Method Details
#include?(pattern) ⇒ Boolean
Does any of the error messages include the regexp pattern? Used to determine whether to retry request.
329 330 331 332 333 334 335 336 |
# File 'lib/gogrid_base.rb', line 329 def include?(pattern) if @errors.is_a?(Array) @errors.each{ |code, msg| return true if code =~ pattern } else return true if @errors_str =~ pattern end false end |