Exception: Jamf::Connection::APIError
- Defined in:
- lib/jamf/api/connection/api_error.rb
Overview
TODO: figure out what to do with ConflictError, BadRequestError, APIRequestError and maybe AuthenticationError
Constant Summary collapse
- RSRC_NOT_FOUND =
- 'Resource Not Found'.freeze 
- ErrorInfo =
          Struct to hold the info for each individual error in an API error response body. Has these attributes (descriptions from developer.jamf.com): code: String Error-specific code that can be used to identify localization string, etc.field: String Name of the field that caused the error.description: String A general description of error for troubleshooting/debugging. Generally this text should not be displayed to a user; instead refer to errorCode and its localized textid: Integer id of object with error. 0 if not applicable
- ImmutableStruct.new(:code, :field, :description, :id) do def to_s deets = "{code: #{code}" deets << ", field: #{field}" if field deets << ", id: #{id}" if id deets << '}' "#{description} #{deets}" end end 
Instance Attribute Summary collapse
- 
  
    
      #errors  ⇒ Array<ErrorInfo> 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    See ErrorInfo above. 
- #http_response ⇒ Faraday::Response readonly
- #httpStatus ⇒ integer (also: #status) readonly
- 
  
    
      #rest_error  ⇒ RestClient::ExceptionWithResponse 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The original RestClient error. 
Instance Method Summary collapse
- 
  
    
      #initialize(http_response)  ⇒ APIError 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of APIError. 
- #to_s ⇒ Object
Constructor Details
#initialize(http_response) ⇒ APIError
Returns a new instance of APIError.
| 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | # File 'lib/jamf/api/connection/api_error.rb', line 83 def initialize(http_response) @http_response = http_response @httpStatus = http_response.status @errors = if @http_response.body.dig :errors @http_response.body[:errors].map { |e| ErrorInfo.new e } else [] end if @errors.empty? code = @httpStatus desc = @httpStatus == 404 ? RSRC_NOT_FOUND : @http_response.reason_phrase @errors << ErrorInfo.new(code: code, field: nil, description: desc, id: nil) end super end | 
Instance Attribute Details
#errors ⇒ Array<ErrorInfo> (readonly)
Returns see ErrorInfo above.
| 77 78 79 | # File 'lib/jamf/api/connection/api_error.rb', line 77 def errors @errors end | 
#http_response ⇒ Faraday::Response (readonly)
| 68 69 70 | # File 'lib/jamf/api/connection/api_error.rb', line 68 def http_response @http_response end | 
#httpStatus ⇒ integer (readonly) Also known as: status
| 72 73 74 | # File 'lib/jamf/api/connection/api_error.rb', line 72 def httpStatus @httpStatus end | 
#rest_error ⇒ RestClient::ExceptionWithResponse (readonly)
Returns the original RestClient error.
| 80 81 82 | # File 'lib/jamf/api/connection/api_error.rb', line 80 def rest_error @rest_error end | 
Instance Method Details
#to_s ⇒ Object
| 103 104 105 | # File 'lib/jamf/api/connection/api_error.rb', line 103 def to_s @errors.map(&:to_s).join '; ' end |