Skip to content

Commit

Permalink
Add logging to Cloudflare client
Browse files Browse the repository at this point in the history
  • Loading branch information
tra0x committed Nov 21, 2024
1 parent e924f49 commit 139b8ef
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/record_store/provider/cloudflare/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,30 @@ def initialize(api_token)

def get(endpoint, params = {})
uri = build_uri(endpoint, params)

response = request(:get, uri)
Cloudflare::Response.new(response)
end

def post(endpoint, body = nil)
uri = build_uri(endpoint)

response = request(:post, uri, body: body)
Cloudflare::Response.new(response)
end

def put(endpoint, body = nil)
uri = build_uri(endpoint)

response = request(:put, uri, body: body)
Cloudflare::Response.new(response)
end

def patch(endpoint, body = nil)
uri = build_uri(endpoint)

response = request(:patch, uri, body: body)
Cloudflare::Response.new(response)
end

def delete(endpoint)
uri = build_uri(endpoint)

response = request(:delete, uri)
Cloudflare::Response.new(response)
end
Expand Down Expand Up @@ -69,10 +64,16 @@ def request(method, uri, body: nil)

begin
response = conn.request(request)
if response.code.to_i >= 500
$stderr.puts "Server error: #{response.code} #{response.message}"
elsif response.code.to_i >= 400
$stderr.puts "Client error: #{response.code} #{response.message}"
end
response
rescue StandardError => e
$stderr.puts "HTTP error: #{e.message}"
raise "HTTP error: #{e.message}"
end
response
end
end

Expand Down

0 comments on commit 139b8ef

Please sign in to comment.