diff --git a/lib/fbe/github_graph.rb b/lib/fbe/github_graph.rb index 444b4cf0..ec066003 100644 --- a/lib/fbe/github_graph.rb +++ b/lib/fbe/github_graph.rb @@ -667,7 +667,12 @@ def client @client ||= begin http = HTTP.new(@token, @host) - schema = GraphQL::Client.load_schema(http) + dump = GraphQL::Client.dump_schema(http) + if dump['data'].nil? + errors = (dump['errors'] || []).map { |e| e['message'] } + raise(Fbe::Error, "Can't load the GraphQL schema from #{@host}: #{errors.empty? ? dump : errors.join('; ')}") + end + schema = GraphQL::Client.load_schema(dump) c = GraphQL::Client.new(schema:, execute: http) c.allow_dynamic_queries = true c diff --git a/test/fbe/test_github_graph.rb b/test/fbe/test_github_graph.rb index 62a2c570..6930b3f2 100644 --- a/test/fbe/test_github_graph.rb +++ b/test/fbe/test_github_graph.rb @@ -1058,4 +1058,16 @@ def test_fake_total_releases_published_dont_count_after_till h = graph.total_releases_published(owner, name, since, till: since + 60) assert_equal(1, h['releases'], "the fake counts releases published after the till moment, seed: #{seed}") end + + def test_explains_failed_schema_load + WebMock.disallow_net_connect! + stub_request(:post, 'https://api.github.com/graphql').to_return( + { status: 401, body: '{"message":"Bad credentials"}' }, + { status: 200, body: '{"errors":[{"message":"API rate limit exceeded"}]}' } + ) + e = assert_raises(Fbe::Error) { Fbe::Graph.new(token: 'x').total_issues_and_pulls('a', 'b') } + assert_includes(e.message, '401', 'The HTTP status must be reported') + e = assert_raises(Fbe::Error) { Fbe::Graph.new(token: 'x').total_issues_and_pulls('a', 'b') } + assert_includes(e.message, 'API rate limit exceeded', 'The message from GitHub must be reported') + end end