Exception: Herbert::Error::ApplicationError
- Inherits:
-
StandardError
- Object
- StandardError
- Herbert::Error::ApplicationError
- Defined in:
- lib/herbert/ApplicationError.rb
Overview
Error relevant in application context
Constant Summary collapse
- Translation =
Code to text translation
{ 1000 => ["Malformated JSON", 400], 1001 => ["Non-unicode encoding",400], 1002 => ["Non-acceptable Accept header", 406], 1003 => ["Not found", 404], 1010 => ["Missing request body", 400], 1011 => ["Missign required parameter", 400], 1012 => ["Invalid request body", 400], 1020 => ["Unspecified error occured", 500] }
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#http_code ⇒ Object
readonly
Returns the value of attribute http_code.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Class Method Summary collapse
-
.merge(errors) ⇒ Object
Add a hash of errors.
-
.push(code, error) ⇒ Object
Add an error.
Instance Method Summary collapse
-
#initialize(errno, http_code = nil, errors = []) ⇒ ApplicationError
constructor
A new instance of ApplicationError.
- #to_hash ⇒ Object
Constructor Details
#initialize(errno, http_code = nil, errors = []) ⇒ ApplicationError
Returns a new instance of ApplicationError.
22 23 24 25 26 27 28 |
# File 'lib/herbert/ApplicationError.rb', line 22 def initialize(errno, http_code = nil, errors = []) raise ArgumentError, "Unknown error code: #{errno}" unless Translation.has_key?(errno.to_i) @code = errno.to_i @message = Translation[@code][0] @http_code = (http_code || Translation[@code][1]) @errors = errors.to_a end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
8 9 10 |
# File 'lib/herbert/ApplicationError.rb', line 8 def code @code end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/herbert/ApplicationError.rb', line 8 def errors @errors end |
#http_code ⇒ Object (readonly)
Returns the value of attribute http_code.
8 9 10 |
# File 'lib/herbert/ApplicationError.rb', line 8 def http_code @http_code end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
8 9 10 |
# File 'lib/herbert/ApplicationError.rb', line 8 def @message end |
Class Method Details
.merge(errors) ⇒ Object
Add a hash of errors
40 41 42 43 44 45 46 |
# File 'lib/herbert/ApplicationError.rb', line 40 def self.merge(errors) if errors.is_a? Hash then Translation.merge!(errors) else raise ArgumentError("Expected a hash of codes and descriptions") end end |
.push(code, error) ⇒ Object
Add an error
35 36 37 |
# File 'lib/herbert/ApplicationError.rb', line 35 def self.push(code, error) Translation[code.to_s] = error.to_a end |
Instance Method Details
#to_hash ⇒ Object
30 31 32 |
# File 'lib/herbert/ApplicationError.rb', line 30 def to_hash { :code => @code, :stackTrace => backtrace, :validationTrace => @errors} end |