Class: EasyqaApi::Exception
- Inherits:
-
Object
- Object
- EasyqaApi::Exception
- Defined in:
- lib/easyqa_api/exceptions.rb
Overview
Class for processing exceptions
Defined Under Namespace
Classes: NotFoundError, PermissionError, RequestError, ValidationError
Constant Summary collapse
- EXCEPTIONS =
Constant for quickly find exception class by response status
{ 404 => NotFoundError, 403 => PermissionError, 400 => RequestError, 422 => ValidationError }.freeze
Class Method Summary collapse
-
.check_response_status!(response) ⇒ Object
Check response status.
-
.retrieve_mess(response_boddy) ⇒ Object
Retrieve message by response body.
Class Method Details
.check_response_status!(response) ⇒ Object
Check response status
35 36 37 38 |
# File 'lib/easyqa_api/exceptions.rb', line 35 def self.check_response_status!(response) raise EXCEPTIONS[response.status], response.body['message'] || retrieve_mess(response.body) \ if EXCEPTIONS[response.status] end |
.retrieve_mess(response_boddy) ⇒ Object
Retrieve message by response body
44 45 46 47 48 |
# File 'lib/easyqa_api/exceptions.rb', line 44 def self.retrieve_mess(response_boddy) response_boddy.each_with_object('') do |(key, values), | << "#{key}: #{values.join('; ')}\n" end end |