Exception: Surveymonkey::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Surveymonkey::Error
- Defined in:
- lib/surveymonkey/error.rb
Constant Summary collapse
- Status_codes =
API status codes, documented upstream.
{ 0 => 'Success', 1 => 'Not Authenticated', 2 => 'Invalid User Credentials', 3 => 'Invalid Request', 4 => 'Unknown User', 5 => 'System Error' }
Instance Attribute Summary collapse
-
#errmsg ⇒ Object
readonly
Returns the value of attribute errmsg.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#status_codes ⇒ Object
readonly
Returns the value of attribute status_codes.
-
#status_name ⇒ Object
readonly
Returns the value of attribute status_name.
Instance Method Summary collapse
-
#initialize(error = {}, status_codes = Status_codes) ⇒ Error
constructor
Create a new Surveymonkey::Error object.
-
#to_s ⇒ Object
Stringify a Surveymonkey::Error object.
Constructor Details
#initialize(error = {}, status_codes = Status_codes) ⇒ Error
Create a new Surveymonkey::Error object. Pass in the hash parsed from the JSON object returned by the API.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/surveymonkey/error.rb', line 24 def initialize(error = {}, status_codes = Status_codes) begin @status_codes = status_codes @status = error.fetch('status', 0) @errmsg = error.fetch('errmsg', '') @status_name = _status_name(@status) rescue StandardError => e $log.error(sprintf("%s: unable to parse '%s' as error", __method__, error.inspect)) raise e end end |
Instance Attribute Details
#errmsg ⇒ Object (readonly)
Returns the value of attribute errmsg.
18 19 20 |
# File 'lib/surveymonkey/error.rb', line 18 def errmsg @errmsg end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
18 19 20 |
# File 'lib/surveymonkey/error.rb', line 18 def status @status end |
#status_codes ⇒ Object (readonly)
Returns the value of attribute status_codes.
18 19 20 |
# File 'lib/surveymonkey/error.rb', line 18 def status_codes @status_codes end |
#status_name ⇒ Object (readonly)
Returns the value of attribute status_name.
18 19 20 |
# File 'lib/surveymonkey/error.rb', line 18 def status_name @status_name end |
Instance Method Details
#to_s ⇒ Object
Stringify a Surveymonkey::Error object.
40 41 42 |
# File 'lib/surveymonkey/error.rb', line 40 def to_s sprintf("Error %i (%s): %s", self.status, self.status_name, self.errmsg) end |