Exception: Jamf::Connection::JamfProAPIError
- Defined in:
- lib/jamf/api/connection/jamf_pro_api_error.rb
Overview
An exception class that’s a wrapper around Jamf::OAPIObject::ApiError
Constant Summary collapse
- RSRC_NOT_FOUND =
'Resource Not Found'.freeze
Instance Attribute Summary collapse
- #api_error ⇒ Jamf::OAPIObject::ApiError readonly
- #http_response ⇒ Faraday::Response readonly
Instance Method Summary collapse
-
#add_common_basic_error_causes ⇒ Object
If no actual errors causes came with the APIError, try to add some common basic ones.
-
#api_status ⇒ Object
http status, from the API error.
-
#errors ⇒ Array<Jamf::OAPIObject::ApiErrorCause>
The causes of the error.
-
#http_status ⇒ Object
http status, from the server http response.
-
#initialize(http_response) ⇒ JamfProAPIError
constructor
A new instance of JamfProAPIError.
-
#to_s ⇒ Object
To string, this shows up as the exception msg when raising the exception.
Constructor Details
#initialize(http_response) ⇒ JamfProAPIError
Returns a new instance of JamfProAPIError.
25 26 27 28 29 30 31 |
# File 'lib/jamf/api/connection/jamf_pro_api_error.rb', line 25 def initialize(http_response) @http_response = http_response @api_error = Jamf::OAPISchemas::ApiError.new @http_response.body add_common_basic_error_causes if @api_error.errors.empty? super end |
Instance Attribute Details
#api_error ⇒ Jamf::OAPIObject::ApiError (readonly)
22 23 24 |
# File 'lib/jamf/api/connection/jamf_pro_api_error.rb', line 22 def api_error @api_error end |
#http_response ⇒ Faraday::Response (readonly)
19 20 21 |
# File 'lib/jamf/api/connection/jamf_pro_api_error.rb', line 19 def http_response @http_response end |
Instance Method Details
#add_common_basic_error_causes ⇒ Object
If no actual errors causes came with the APIError, try to add some common basic ones
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/jamf/api/connection/jamf_pro_api_error.rb', line 35 def add_common_basic_error_causes return unless api_error.errors.empty? case http_response.status when 403 code = 'INVALID_PRIVILEGE' desc = 'Forbidden' id = nil field = '' when 404 code = 'NOT_FOUND' desc = "'#{http_response.env.url.path}' was not found on the server" id = nil field = '' else return end # case api_error.errors_append Jamf::OAPISchemas::ApiErrorCause.new(field: field, code: code, description: desc, id: id) end |
#api_status ⇒ Object
http status, from the API error
62 63 64 |
# File 'lib/jamf/api/connection/jamf_pro_api_error.rb', line 62 def api_status api_error.httpStatus end |
#errors ⇒ Array<Jamf::OAPIObject::ApiErrorCause>
Returns the causes of the error.
67 68 69 |
# File 'lib/jamf/api/connection/jamf_pro_api_error.rb', line 67 def errors api_error.errors end |
#http_status ⇒ Object
http status, from the server http response
57 58 59 |
# File 'lib/jamf/api/connection/jamf_pro_api_error.rb', line 57 def http_status http_response.status end |
#to_s ⇒ Object
To string, this shows up as the exception msg when raising the exception
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/jamf/api/connection/jamf_pro_api_error.rb', line 72 def to_s msg = +"HTTP #{http_status}" msg << ':' unless errors.empty? msg << errors.map do |err| err_str = +'' err_str << " Field: #{err.field}" unless err.field.to_s.empty? err_str << ', Error:' if err.code || err.description err_str << ", #{err.code}" if err.code err_str << ", #{err.description}" if err.description err_str << ", Object ID: '#{err.id}'" if err.id err_str end.join('; ') msg end |