Jira issues - Consider including Jira response in error message displayed to user
Proposal
We previously improved some of the error messages around Jira issues in here. However, I believe we could further improve this by also including the error message sent from Jira and surfacing this to users.
For example, when the Jira project key used in the configuration does not exist, this is what our UI shows:
An error occurred while requesting data from Jira. Check your Jira integration configuration and try again.
and this is what the response from Jira looks like:
{"errorMessages"=>["The value 'AB' does not exist for the field 'project'."], "warningMessages"=>[]}
I think adding the raw error from Jira to our own message will help users get a bit more context and hopefully be able to troubleshoot their configuration without help from our support team.
Using the below diff, I was able to extract this error message, though properly raising the error and returning it in logs / UI might take a bit more work.
diff --git a/lib/gitlab/jira/http_client.rb b/lib/gitlab/jira/http_client.rb
index 7abfe8e38e82..37d4f92b1907 100644
--- a/lib/gitlab/jira/http_client.rb
+++ b/lib/gitlab/jira/http_client.rb
@@ -11,8 +11,11 @@ class HttpClient < JIRA::HttpClient
override :request
def request(*args)
result = make_request(*args)
-
- raise JIRA::HTTPError, result.response unless result.response.is_a?(Net::HTTPSuccess)
+ error_message = JSON.parse(result.response.body)['errorMessages'].join(' ')
+ Rails.logger.debug '=========RESPONSE IS HERE========'
+ Rails.logger.debug error_message
+ Rails.logger.debug '=========RESPONSE IS HERE========'
+ raise JIRA::HTTPError, error_message unless result.response.is_a?(Net::HTTPSuccess)
result
end