Fix undefined response in reindexing Grafana notifier
What does this MR do and why
notify_start and notify_end discarded the HTTP response and kept only
.success?, but the line right after asks response.code:
success = Gitlab::HTTP.post(...).success?
log_error("Response code #{response.code}") unless successresponse is not a local variable, not a method on the class and not
inherited: the class has no superclass and no include, so the call raises
NameError. NameError is a StandardError, so the rescue StandardError
right below catches it and logs its message instead. The practical effect is
that the Grafana status code is replaced by a generic message precisely when
the annotation request failed, which is the moment the line exists to
report.
This MR captures the response and derives success from it, so the failure
path logs the code it always meant to log.
The spec was encoding the bug
The failure example passed before this change for the wrong reason. Its
response double only stubs success?, so response.code raised
NameError, the rescue swallowed it, and the example's be_falsey
assertion still held. With the fix, the line actually runs and the double
receives an unexpected :code.
So the spec is updated rather than merely repaired: it now stubs code and
asserts that the failure path logs the status code, which is the behaviour
this MR restores. The example fails without the production change and
passes with it.
How to verify
The class has ten methods and no ancestor providing response, so the read
cannot resolve at runtime. Reading the full class is the check here: a grep
for def response is not enough, because an attr_reader would not show up
in it.
Spotted by itaruby(to be released), a Ruby type checker I'm working on.