Skip to content

Commit eb01de5

Browse files
authored
misc(http-client): Add response headers to http error (#3344)
## Description This PR adds response headers to `LagoHttpClient::HttpError` which will help us to debug requests made to external integrations services.
1 parent 063b3f0 commit eb01de5

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

lib/lago_http_client/lago_http_client/client.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ def get(headers: {}, params: nil, body: nil)
114114
attr_reader :http_client
115115

116116
def raise_error(response)
117-
raise(::LagoHttpClient::HttpError.new(response.code, response.body, uri))
117+
raise(
118+
::LagoHttpClient::HttpError.new(response.code, response.body, uri, response_headers: response.each_header.to_h)
119+
)
118120
end
119121
end
120122
end

lib/lago_http_client/lago_http_client/http_error.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
module LagoHttpClient
44
class HttpError < StandardError
5-
attr_reader :error_code, :error_body, :uri
5+
attr_reader :error_code, :error_body, :uri, :response_headers
66

7-
def initialize(code, body, uri)
7+
def initialize(code, body, uri, response_headers: {})
88
@error_code = code
99
@error_body = body
1010
@uri = uri
11+
@response_headers = response_headers
1112
end
1213

1314
def message
14-
"HTTP #{error_code} - URI: #{uri}.\nError: #{error_body}"
15+
"HTTP #{error_code} - URI: #{uri}.\nError: #{error_body}\nResponse headers: #{response_headers}"
1516
end
1617

1718
def json_message

0 commit comments

Comments
 (0)