Jira integration: Handle non-JSON responses from unauthenticated requests
## Summary
GitLab's Jira integration fails with a cryptic JSON parsing error when Atlassian Jira returns an unauthenticated response that is not in JSON format. This commonly occurs when invalid credentials are provided or when the authentication endpoint is misconfigured.
## Problem Description
**Error message:**
```
Connection failed. Check your integration settings. unexpected character: 'Client' at line 1 column 1
```
**Steps to reproduce:**
1. Configure a Jira integration with invalid or incomplete credentials. See below for an example.
2. Test the connection
3. Observe the JSON parsing error by piping this through `jq` instead of a clear authentication failure message
#### Example:
```
JIRA_URL="https://bking-gitlab.atlassian.net" # must be a valid site
JIRA_EMAIL="user@example.com"
JIRA_API_TOKEN="wrong-or-real-token"
curl -v -i \
-u "${JIRA_EMAIL}:${JIRA_API_TOKEN}" \
-H "Accept: application/json" \
"${JIRA_URL}/rest/api/2/myself"
```
Response:
```
Client must be authenticated to access this resource.
```
If piped through to `jq`, it can't handle this response properly:
```
jq: parse error: Invalid numeric literal at line 1, column 7
```
**Current behavior:**
- GitLab attempts to parse the HTTP response as JSON
- When Atlassian returns an HTML error page or plain text response (typical for 401/403 errors), the JSON parser fails
- Users see a confusing error message about unexpected characters rather than understanding the authentication failed
**Expected behavior:**
- GitLab should detect non-JSON responses and provide a clear error message indicating authentication failure
- The error should guide users to check their credentials and integration settings
## Root Cause
When Atlassian Jira rejects a request due to invalid authentication, it may return:
- HTTP 401/403 status codes
- HTML error pages instead of JSON
- Plain text responses
GitLab's integration code attempts to parse these responses as JSON without first validating the response format or checking the Content-Type header, resulting in a JSON parsing exception.
## Technical Details
The error `unexpected character: 'Client' at line 1 column 1` suggests the response starts with the word "Client" (likely from an HTML error page like "Client Error" or similar), which is not valid JSON.
## Proposed Solution
1. **Validate response format** before attempting JSON parsing
2. **Check Content-Type header** to determine if response is JSON
3. **Handle HTTP error status codes** gracefully with appropriate error messages
4. **Provide clear feedback** to users about authentication failures vs. other connection issues
## Related Issues
- [#576326](https://gitlab.com/gitlab-org/gitlab/-/work_items/576326) - Jira Service Account Authentication Support
## Labels
~"type::bug" ~"group::project management" ~"Category:Integrations" ~"Integration::Jira"
issue