Class: ElephantInTheRoom::TheOneApiSdk::Pipeline::RaiseHttpErrors

Inherits:
Object
  • Object
show all
Defined in:
lib/elephant_in_the_room/the_one_api_sdk/pipeline/raise_http_errors.rb

Overview

Pipeline stage that raises errors when the HTTP response is a 4xx or 5xx error

Instance Method Summary collapse

Constructor Details

#initialize(next_pipeline_stage) ⇒ RaiseHttpErrors



9
10
11
# File 'lib/elephant_in_the_room/the_one_api_sdk/pipeline/raise_http_errors.rb', line 9

def initialize(next_pipeline_stage)
  @next_pipeline_stage = next_pipeline_stage
end

Instance Method Details

#execute_http_request(request_details) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/elephant_in_the_room/the_one_api_sdk/pipeline/raise_http_errors.rb', line 13

def execute_http_request(request_details)
  response = @next_pipeline_stage.execute_http_request(request_details)
  if response.is_a? Net::HTTPServerError
    raise ElephantInTheRoom::TheOneApiSdk::Errors::ServerError, response
  elsif response.is_a? Net::HTTPClientError
    raise ElephantInTheRoom::TheOneApiSdk::Errors::ClientError, response
  end
end

#http_responseObject



22
23
24
# File 'lib/elephant_in_the_room/the_one_api_sdk/pipeline/raise_http_errors.rb', line 22

def http_response
  @next_pipeline_stage.http_response
end