Skip to content

Commit 49d4638

Browse files
committed
WIP
1 parent d34253e commit 49d4638

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/content_item_loader.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ def load_from_sources(base_path)
3030
load_json_file(base_path)
3131
elsif use_graphql?
3232
graphql_response = GdsApi.publishing_api.graphql_content_item(Graphql::EditionQuery.new(base_path).query)
33-
if GRAPHQL_ALLOWED_SCHEMAS.include?(graphql_response["schema_name"])
34-
graphql_response
33+
debugger
34+
if graphql_response.to_hash.key?("errors")
35+
set_prometheus_labels("contains_errors" => true)
36+
elsif GRAPHQL_ALLOWED_SCHEMAS.include?(graphql_response["schema_name"])
37+
graphql_response
3538
else
3639
GdsApi.content_store.content_item(base_path)
3740
end
@@ -88,4 +91,12 @@ def load_json_file(base_path)
8891
def headers
8992
{ cache_control: "max-age=0, public", expires: "" }
9093
end
94+
95+
def set_prometheus_labels(hash)
96+
return unless hash
97+
98+
prometheus_labels = request.env.fetch("govuk.prometheus_labels", {})
99+
100+
request.env["govuk.prometheus_labels"] = prometheus_labels.merge(hash)
101+
end
91102
end

spec/unit/content_item_loader_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@
219219
expect(item_request).not_to have_been_made
220220
end
221221
end
222+
223+
context "given a response from graphql containing errors" do #pick this up here tomorrow
224+
subject(:content_item_loader) { described_class.for_request(request) }
225+
226+
let!(:graphql_request) { stub_publishing_api_graphql_query(graphql_query, { data: { edition: { schema_name: "news_article" } } }) }
227+
let(:request) { instance_double(ActionDispatch::Request, path: "/my-random-item", env: {}, params: { "graphql" => "true" }) }
228+
222229
end
223230

224231
context "when the content item schema is not in GRAPHQL_ALLOWED_SCHEMAS" do

0 commit comments

Comments
 (0)