def response_handler(response, wait_on_task = true)
      case response.code.to_i
      when RESPONSE_CODE_OK # Synchronous read/query
        begin
          return JSON.parse(response.body)
        rescue JSON::ParserError => e
          @logger.warn "Failed to parse JSON response. #{e}"
          return response.body
        end
      when RESPONSE_CODE_CREATED # Synchronous add
        JSON.parse(response.body)
      when RESPONSE_CODE_ACCEPTED # Asynchronous add, update or delete
        return JSON.parse(response.body) unless wait_on_task
        @logger.debug "Waiting for task: response.header['location']"
        uri = response.header['location'] || JSON.parse(response.body)['uri'] # If task uri is not returned in header
        task = wait_for(uri)
        return true unless task['associatedResource'] && task['associatedResource']['resourceUri']
        resource_data = rest_get(task['associatedResource']['resourceUri'])
        JSON.parse(resource_data.body)
      when RESPONSE_CODE_NO_CONTENT # Synchronous delete
        {}
      when RESPONSE_CODE_BAD_REQUEST
        BadRequest.raise! "400 BAD REQUEST #{response.body}", response
      when RESPONSE_CODE_UNAUTHORIZED
        Unauthorized.raise! "401 UNAUTHORIZED #{response.body}", response
      when RESPONSE_CODE_NOT_FOUND
        NotFound.raise! "404 NOT FOUND #{response.body}", response
      else
        RequestError.raise! "#{response.code} #{response.body}", response
      end
    end
def response_handler(response, wait_on_task = true)
      case response.code.to_i
      when RESPONSE_CODE_OK # Synchronous read/query
        begin
          return JSON.parse(response.body)
        rescue JSON::ParserError => e
          @logger.warn "Failed to parse JSON response. #{e}"
          return response.body
        end
      when RESPONSE_CODE_CREATED # Synchronous add
        JSON.parse(response.body)
      when RESPONSE_CODE_ACCEPTED # Asynchronous add, update or delete
        return JSON.parse(response.body) unless wait_on_task
        @logger.debug "Waiting for task: response.header['location']"
        uri = response.header['location'] || JSON.parse(response.body)['uri'] # If task uri is not returned in header
        task = wait_for(uri)
        return true unless task['associatedResource'] && task['associatedResource']['resourceUri']
        resource_data = rest_get(task['associatedResource']['resourceUri'])
        JSON.parse(resource_data.body)
      when RESPONSE_CODE_NO_CONTENT # Synchronous delete
        {}
      when RESPONSE_CODE_BAD_REQUEST
        BadRequest.raise! "400 BAD REQUEST #{response.body}", response
      when RESPONSE_CODE_UNAUTHORIZED
        Unauthorized.raise! "401 UNAUTHORIZED #{response.body}", response
      when RESPONSE_CODE_NOT_FOUND
        NotFound.raise! "404 NOT FOUND #{response.body}", response
      else
        RequestError.raise! "#{response.code} #{response.body}", response
      end
    end
Handles the response from a rest call.
   If an asynchronous task was started, this waits for it to complete.
 @param [HTTPResponse] response HTTP response
 @param [Boolean] wait_on_task Wait on task (or just return task details)
 @raise [OneviewSDK::OneViewError] if the request failed or a task did not complete successfully
 @return [Hash] The parsed JSON body