14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/slack_webhook_logger/request_io.rb', line 14
def write(hash)
return if hash.blank?
return if SlackWebhookLogger.ignore_patterns.any? { |ignore_pattern| SlackWebhookLogger::Formatter.fetch_text(hash).match(ignore_pattern) }
response = HTTPX.with(headers: { "content-type" => "application/json" }).post(SlackWebhookLogger.webhook_uri.to_s, json: hash)
return if (200..299).cover?(response.status)
error_prefix = "slack_webhook_logger failed.\nRequest: #{hash}\nResponse:"
case response
when HTTPX::ErrorResponse
warn("#{error_prefix} #{response}")
else
warn("#{error_prefix} #{response.status} #{response.body}")
end
end
|