class Jamf::Connection::JamfProAPIError
An exception class that’s a wrapper around Jamf::OAPIObject::ApiError
Constants
- RSRC_NOT_FOUND
Attributes
api_error[R]
@return [Jamf::OAPIObject::ApiError]
http_response[R]
@return [Faraday::Response]
Public Class Methods
new(http_response)
click to toggle source
@param http_response
[Faraday::Response]
Calls superclass method
# File lib/jamf/api/connection/jamf_pro_api_error.rb 43 def initialize(http_response) 44 @http_response = http_response 45 @api_error = Jamf::OAPISchemas::ApiError.new @http_response.body 46 47 add_common_basic_error_causes if @api_error.errors.empty? 48 super 49 end
Public Instance Methods
add_common_basic_error_causes()
click to toggle source
If no actual errors causes came with the APIError, try to add some common basic ones
# File lib/jamf/api/connection/jamf_pro_api_error.rb 53 def add_common_basic_error_causes 54 return unless api_error.errors.empty? 55 56 case http_response.status 57 when 403 58 code = 'INVALID_PRIVILEGE' 59 desc = 'Forbidden' 60 id = nil 61 field = '' 62 when 404 63 code = 'NOT_FOUND' 64 desc = "'#{http_response.env.url.path}' was not found on the server" 65 id = nil 66 field = '' 67 else 68 return 69 end # case 70 71 api_error.errors_append Jamf::OAPISchemas::ApiErrorCause.new(field: field, code: code, description: desc, id: id) 72 end
api_status()
click to toggle source
http status, from the API error
# File lib/jamf/api/connection/jamf_pro_api_error.rb 80 def api_status 81 api_error.httpStatus 82 end
errors()
click to toggle source
@return [Array<Jamf::OAPIObject::ApiErrorCause>] the causes of the error
# File lib/jamf/api/connection/jamf_pro_api_error.rb 85 def errors 86 api_error.errors 87 end
http_status()
click to toggle source
http status, from the server http response
# File lib/jamf/api/connection/jamf_pro_api_error.rb 75 def http_status 76 http_response.status 77 end
to_s()
click to toggle source
To string, this shows up as the exception msg when raising the exception
# File lib/jamf/api/connection/jamf_pro_api_error.rb 90 def to_s 91 msg = +"HTTP #{http_status}" 92 msg << ':' unless errors.empty? 93 msg << errors.map do |err| 94 err_str = +'' 95 err_str << " Field: #{err.field}" unless err.field.to_s.empty? 96 err_str << ' Error:' if err.code || err.description 97 err_str << " #{err.code}" if err.code 98 err_str << " #{err.description}" if err.description 99 err_str << " Object ID: '#{err.id}'" if err.id 100 err_str 101 end.join('; ') 102 msg 103 end