Class: Responses::ExceptionResponse

Inherits:
BaseResponse show all
Defined in:
lib/nasa/utils/responses.rb

Overview

Handles and parses error responses from the API

Instance Attribute Summary

Attributes inherited from BaseResponse

#body, #code, #headers, #message, #raw_response, #remaining_requests

Instance Method Summary collapse

Methods inherited from BaseResponse

#[]

Constructor Details

#initialize(response) ⇒ ExceptionResponse

Returns a new instance of ExceptionResponse



69
70
71
# File 'lib/nasa/utils/responses.rb', line 69

def initialize(response)
  super(response)
end

Instance Method Details

#parse_response(response) ⇒ Hash

Parses response from failed API calls

Parameters:

  • response (RestClient::ExceptionWithResponse)

Returns:

  • (Hash)

    Parsed JSON body from response



77
78
79
80
81
82
# File 'lib/nasa/utils/responses.rb', line 77

def parse_response(response)
  @code = response.http_code
  @body = json_parse(response.http_body)
  @message = @body.dig(:error, :message)
  @headers = response.http_headers
end