Exception: APIException
- Inherits:
-
StandardError
- Object
- StandardError
- APIException
- Defined in:
- lib/carehq/exceptions.rb
Direct Known Subclasses
Forbidden, InvalidRequest, NotFound, RateLimitExceeded, Unauthorized
Instance Attribute Summary collapse
-
#arg_errors ⇒ Object
readonly
Returns the value of attribute arg_errors.
-
#hint ⇒ Object
readonly
Returns the value of attribute hint.
-
#status_code ⇒ Object
readonly
An error occurred while processing an API the request.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(status_code, hint = nil, arg_errors = nil) ⇒ APIException
constructor
A new instance of APIException.
Constructor Details
#initialize(status_code, hint = nil, arg_errors = nil) ⇒ APIException
Returns a new instance of APIException.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/carehq/exceptions.rb', line 10 def initialize(status_code, hint=nil, arg_errors=nil) # The status code associated with the error @status_code = status_code # A hint providing additional information as to why this error # occurred. @hint = hint # A dictionary of errors relating to the arguments (parameters) sent # to the API endpoint (e.g `{'arg_name': ['error1', ...]}`). @arg_errors = arg_errors super() end |
Instance Attribute Details
#arg_errors ⇒ Object (readonly)
Returns the value of attribute arg_errors.
8 9 10 |
# File 'lib/carehq/exceptions.rb', line 8 def arg_errors @arg_errors end |
#hint ⇒ Object (readonly)
Returns the value of attribute hint.
7 8 9 |
# File 'lib/carehq/exceptions.rb', line 7 def hint @hint end |
#status_code ⇒ Object (readonly)
An error occurred while processing an API the request.
6 7 8 |
# File 'lib/carehq/exceptions.rb', line 6 def status_code @status_code end |
Class Method Details
.get_class_by_status_code(error_type, default = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/carehq/exceptions.rb', line 26 def APIException.get_class_by_status_code(error_type, default=nil) class_map = { 400 => InvalidRequest, 401 => Unauthorized, 403 => Forbidden, 405 => Forbidden, 404 => NotFound, 429 => RateLimitExceeded } if class_map.has_key? error_type return class_map[error_type] elsif default return default end return APIException end |