Method: AptlyCli::AptlyCommand#process_response

Defined in:
lib/aptly_command.rb

#process_response(response) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/aptly_command.rb', line 92

def process_response(response)
  json_response = JSON.parse response.body

  raise "[Server] #{json_response['error']}" unless !json_response.is_a?(Hash) || json_response.dig('error').nil?

  raise HttpNotFoundError, "[HTTP Not Found Error] JSON response:\n#{json_response}" if response.code == 404
  raise HttpInternalServerError, "[HTTP Internal Server Error] JSON response:\n#{json_response}" if response.code == 500

  response
rescue JSON::ParserError
  raise HttpNotFoundError, "[HTTP Not Found Error] Response:\n#{response.body}" if response.code == 404
  raise HttpInternalServerError, "[HTTP Internal Server Error] Response:\n#{response.body}" if response.code == 500

  response
end