Skip to content

Commit

Permalink
Print the HTTP status as the failure reason. (#21051)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerluan committed Oct 16, 2023
1 parent fd0f4c3 commit 24dc3b7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion precheck/lib/precheck/rules/unreachable_urls_rule.rb
Expand Up @@ -33,7 +33,7 @@ def rule_block
connection.use(FaradayMiddleware::FollowRedirects)
connection.adapter(:net_http)
end
return RuleReturn.new(validation_state: Precheck::VALIDATION_STATES[:failed], failure_data: url) unless request.head.status == 200
return RuleReturn.new(validation_state: Precheck::VALIDATION_STATES[:failed], failure_data: "HTTP #{request.head.status}: #{url}") unless request.head.status == 200
rescue StandardError => e
UI.verbose("URL #{url} not reachable 馃樀: #{e.message}")
# I can only return :fail here, but I also want to return #{url}
Expand Down
8 changes: 4 additions & 4 deletions precheck/spec/rules/unreachable_urls_rule_spec.rb
Expand Up @@ -42,22 +42,22 @@ def setup_url_rule_mock(url: "http://fastlane.tools", return_status: 200)

result = rule.check_item(item)
expect(result.status).to eq(VALIDATION_STATES[:failed])
expect(result.rule_return.failure_data).to eq("http://fastlane.tools")
expect(result.rule_return.failure_data).to eq("HTTP 500: http://fastlane.tools")

setup_url_rule_mock(return_status: 404)
result = rule.check_item(item)
expect(result.status).to eq(VALIDATION_STATES[:failed])
expect(result.rule_return.failure_data).to eq("http://fastlane.tools")
expect(result.rule_return.failure_data).to eq("HTTP 404: http://fastlane.tools")

setup_url_rule_mock(return_status: 409)
result = rule.check_item(item)
expect(result.status).to eq(VALIDATION_STATES[:failed])
expect(result.rule_return.failure_data).to eq("http://fastlane.tools")
expect(result.rule_return.failure_data).to eq("HTTP 409: http://fastlane.tools")

setup_url_rule_mock(return_status: 403)
result = rule.check_item(item)
expect(result.status).to eq(VALIDATION_STATES[:failed])
expect(result.rule_return.failure_data).to eq("http://fastlane.tools")
expect(result.rule_return.failure_data).to eq("HTTP 403: http://fastlane.tools")
end

it "fails if not optional and URL is nil" do
Expand Down

0 comments on commit 24dc3b7

Please sign in to comment.