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.
43 44 45 46 47 48 49 |
# File 'lib/jamf/api/connection/jamf_pro_api_error.rb', line 43 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)
40 41 42 |
# File 'lib/jamf/api/connection/jamf_pro_api_error.rb', line 40 def api_error @api_error end |
#http_response ⇒ Faraday::Response (readonly)
37 38 39 |
# File 'lib/jamf/api/connection/jamf_pro_api_error.rb', line 37 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
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/jamf/api/connection/jamf_pro_api_error.rb', line 53 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
80 81 82 |
# File 'lib/jamf/api/connection/jamf_pro_api_error.rb', line 80 def api_status api_error.httpStatus end |
#errors ⇒ Array<Jamf::OAPIObject::ApiErrorCause>
Returns the causes of the error.
85 86 87 |
# File 'lib/jamf/api/connection/jamf_pro_api_error.rb', line 85 def errors api_error.errors end |
#http_status ⇒ Object
http status, from the server http response
75 76 77 |
# File 'lib/jamf/api/connection/jamf_pro_api_error.rb', line 75 def http_status http_response.status end |
#to_s ⇒ Object
To string, this shows up as the exception msg when raising the exception
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/jamf/api/connection/jamf_pro_api_error.rb', line 90 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 |