diff --git a/src/coverage_reporter/api.cr b/src/coverage_reporter/api.cr index 663642dd..2e785e65 100644 --- a/src/coverage_reporter/api.cr +++ b/src/coverage_reporter/api.cr @@ -52,6 +52,19 @@ module CoverageReporter OpenSSL::SSL::Context::Client.insecure end + def with_ssl_errors_handling() : HTTP::Client::Response + begin + yield + rescue ex + if OpenSSLVersion.new.can_fail? + Log.error <<-ERROR + Consider upgrading `openssl` library to version >= #{OpenSSLVersion::WORKS} or using --force-insecure-requests flag + ERROR + end + raise(ex) + end + end + def with_redirects(uri : URI, max_redirects : Int32 = 10, & : URI -> HTTP::Client::Response) : HTTP::Client::Response redirect_num = 0 response = yield(uri) diff --git a/src/coverage_reporter/api/jobs.cr b/src/coverage_reporter/api/jobs.cr index a9ff8a42..d0e0b11d 100644 --- a/src/coverage_reporter/api/jobs.cr +++ b/src/coverage_reporter/api/jobs.cr @@ -64,12 +64,14 @@ module CoverageReporter headers.merge!(HTTP::Headers{"Content-Type" => content_type.gsub("\"", "")}) response = Api.with_redirects(jobs_uri) do |uri| - HTTP::Client.post( - uri, - body: body, - headers: headers, - tls: Api.tls_for(uri, @config.force_insecure_requests) - ) + Api.with_ssl_errors_handling do + HTTP::Client.post( + uri, + body: body, + headers: headers, + tls: Api.tls_for(uri, @config.force_insecure_requests) + ) + end end Api.handle_response(response) diff --git a/src/coverage_reporter/api/webhook.cr b/src/coverage_reporter/api/webhook.cr index 82547441..0048d752 100644 --- a/src/coverage_reporter/api/webhook.cr +++ b/src/coverage_reporter/api/webhook.cr @@ -35,12 +35,14 @@ module CoverageReporter }) res = Api.with_redirects(webhook_uri) do |uri| - HTTP::Client.post( - uri, - headers: headers, - body: data.to_json, - tls: Api.tls_for(uri, @config.force_insecure_requests) - ) + Api.with_ssl_errors_handling do + HTTP::Client.post( + uri, + headers: headers, + body: data.to_json, + tls: Api.tls_for(uri, @config.force_insecure_requests) + ) + end end Api.handle_response(res)