Exception: Judopay::APIError
- Inherits:
-
StandardError
- Object
- StandardError
- Judopay::APIError
- Defined in:
- lib/judopay/error.rb
Overview
Custom error class for rescuing from all API errors
Constant Summary collapse
- CATEGORY_UNKNOWN =
0
- CATEGORY_REQUEST =
1
- CATEGORY_MODEL =
2
- CATEGORY_CONFIG =
3
- CATEGORY_PROCESSING =
4
- CATEGORY_EXCEPTION =
5
Instance Attribute Summary collapse
-
#category ⇒ Object
Returns the value of attribute category.
-
#error_code ⇒ Object
Returns the value of attribute error_code.
-
#field_errors ⇒ Object
Returns the value of attribute field_errors.
- #message ⇒ Object
-
#status_code ⇒ Object
Returns the value of attribute status_code.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(message, error_code = 0, status_code = 0, category = CATEGORY_UNKNOWN, field_errors = []) ⇒ APIError
constructor
A new instance of APIError.
- #to_s ⇒ Object
Constructor Details
#initialize(message, error_code = 0, status_code = 0, category = CATEGORY_UNKNOWN, field_errors = []) ⇒ APIError
Returns a new instance of APIError.
63 64 65 66 67 68 69 |
# File 'lib/judopay/error.rb', line 63 def initialize(, error_code = 0, status_code = 0, category = CATEGORY_UNKNOWN, field_errors = []) @message = @error_code = error_code @status_code = status_code @category = category @field_errors = field_errors end |
Instance Attribute Details
#category ⇒ Object
Returns the value of attribute category.
29 30 31 |
# File 'lib/judopay/error.rb', line 29 def category @category end |
#error_code ⇒ Object
Returns the value of attribute error_code.
29 30 31 |
# File 'lib/judopay/error.rb', line 29 def error_code @error_code end |
#field_errors ⇒ Object
Returns the value of attribute field_errors.
29 30 31 |
# File 'lib/judopay/error.rb', line 29 def field_errors @field_errors end |
#message ⇒ Object
75 76 77 |
# File 'lib/judopay/error.rb', line 75 def (@message || self.class.name) + end |
#status_code ⇒ Object
Returns the value of attribute status_code.
29 30 31 |
# File 'lib/judopay/error.rb', line 29 def status_code @status_code end |
Class Method Details
.factory(response) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/judopay/error.rb', line 34 def factory(response) parsed_body = JSON.parse(response.body) new( parsed_body['message'], parsed_body['code'], response.status.to_i, parsed_body['category'], extract_field_errors(parsed_body['details']) ) end |
Instance Method Details
#to_s ⇒ Object
71 72 73 |
# File 'lib/judopay/error.rb', line 71 def to_s "JudoPay ApiException (status code #{@status_code}, error code #{@error_code}, category #{@category}) #{}" end |