fix(jira): always return HTTP 200 from jira-test + strip trailing slash
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled
- jira-test now returns {status: "ok"|"error", message: ...} with
HTTP 200 so Cloudflare never intercepts the response
- jira_service strips trailing slash from URL before creating Jira
client (avoids double-slash in REST paths)
- Frontend reads data.status field instead of HTTP status code
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -295,8 +295,11 @@ def test_jira_connection(
|
||||
|
||||
try:
|
||||
jira = get_user_jira_client(current_user, db)
|
||||
# Lightweight call: get current user info (10 s hard timeout)
|
||||
jira._session.timeout = 10 # type: ignore[attr-defined]
|
||||
# 10-second timeout so we never block Cloudflare into a 524
|
||||
try:
|
||||
jira._session.timeout = 10 # type: ignore[attr-defined]
|
||||
except Exception:
|
||||
pass
|
||||
myself = jira.myself()
|
||||
return {
|
||||
"status": "ok",
|
||||
@@ -305,21 +308,26 @@ def test_jira_connection(
|
||||
}
|
||||
except Exception as exc:
|
||||
err = str(exc)
|
||||
# Translate common Atlassian-library errors into human-readable messages
|
||||
# Always return HTTP 200 with status="error" so Cloudflare never
|
||||
# intercepts the response and the frontend always sees our message.
|
||||
if "Expecting value" in err or "line 1 column 1" in err:
|
||||
detail = (
|
||||
"Jira returned an unexpected response — check that the URL is correct "
|
||||
"and that the account email + API token are valid."
|
||||
msg = (
|
||||
"Jira returned a non-JSON response. "
|
||||
"Verify the URL (e.g. https://company.atlassian.net), "
|
||||
"email and API token."
|
||||
)
|
||||
elif "401" in err or "Unauthorized" in err:
|
||||
detail = "Authentication failed (401). Verify your Atlassian email and API token."
|
||||
msg = "Authentication failed (401). Check your Atlassian email and API token."
|
||||
elif "403" in err or "Forbidden" in err:
|
||||
detail = "Access denied (403). The token may not have permission to access this Jira instance."
|
||||
msg = "Access denied (403). The token may not have permission for this Jira project."
|
||||
elif "timed out" in err.lower() or "timeout" in err.lower():
|
||||
detail = "Connection timed out. Check the Jira URL is reachable from the server."
|
||||
msg = "Connection timed out. Check that the Jira URL is reachable from the server."
|
||||
elif "not configured" in err.lower():
|
||||
msg = err
|
||||
else:
|
||||
detail = f"Jira connection failed: {err}"
|
||||
raise HTTPException(status_code=502, detail=detail)
|
||||
msg = f"Jira connection failed: {err}"
|
||||
logger.warning("Jira test connection failed: %s", err)
|
||||
return {"status": "error", "message": msg, "jira_url": jira_url}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user