Skip to content

Handle error: JiraError HTTP 400 #20

@jarp0l

Description

@jarp0l

Is your feature request related to a problem? Please describe.
While using the jira_scan command to scan Jira projects/issues, some projects only allowed me to view information like project name and project lead but not issues. So this caused the tool to not proceed to scanning the rest of the projects, and throwing JiraError HTTP 400 continuously.

Part of the error log:

JiraError HTTP 400 url: https://abcd.atlassian.net/rest/api/2/search?jql=project+%3D+%27XY%27&startAt=0&validateQuery=True&fields=%2Aall&maxResults=50
	text: The value 'XY' does not exist for the field 'project'.
	
	response headers = {'Date': 'Tue, 02 Jul 2024 11:37:32 GMT', 'Content-Type': 'application/json;charset=UTF-8', 'Server': 'AtlassianEdge', 'Timing-Allow-Origin': '*', 'X-Arequestid': 'REDACTED', 'X-Aaccountid': 'REDACTED', 'Cache-Control': 'no-cache, no-store, no-transform', 'X-Content-Type-Options': 'nosniff', 'X-Xss-Protection': '1; mode=block', 'Atl-Traceid': 'REDACTED', 'Strict-Transport-Security': 'max-age=63072000; includeSubDomains; preload', 'Report-To': '{"endpoints": [{"url": "https://dy8abcen1416s.cloudfront.net"}], "group": "endpoint-1", "include_subdomains": true, "max_age": 600}', 'Nel': '{"failure_fraction": 0.001, "include_subdomains": true, "max_age": 600, "report_to": "endpoint-1"}', 'Transfer-Encoding': 'chunked'}
	response text = {"errorMessages":["The value 'XY' does not exist for the field 'project'."],"warningMessages":[]} client.search_issues(project = 'XY', startAt=0, maxResults=50)
JiraError HTTP 400 url: https://abcd.atlassian.net/rest/api/2/search?jql=project+%3D+%27XY%27&startAt=0&validateQuery=True&fields=%2Aall&maxResults=50
	text: The value 'XY' does not exist for the field 'project'.
	
	response headers = {'Date': 'Tue, 02 Jul 2024 11:37:34 GMT', 'Content-Type': 'application/json;charset=UTF-8', 'Server': 'AtlassianEdge', 'Timing-Allow-Origin': '*', 'X-Arequestid': 'REDACTED', 'X-Aaccountid': 'REDACTED', 'Cache-Control': 'no-cache, no-store, no-transform', 'X-Content-Type-Options': 'nosniff', 'X-Xss-Protection': '1; mode=block', 'Atl-Traceid': 'REDACTED', 'Strict-Transport-Security': 'max-age=63072000; includeSubDomains; preload', 'Report-To': '{"endpoints": [{"url": "https://dy8abcen1416s.cloudfront.net"}], "group": "endpoint-1", "include_subdomains": true, "max_age": 600}', 'Nel': '{"failure_fraction": 0.001, "include_subdomains": true, "max_age": 600, "report_to": "endpoint-1"}', 'Transfer-Encoding': 'chunked'}
	response text = {"errorMessages":["The value 'XY' does not exist for the field 'project'."],"warningMessages":[]} client.search_issues(project = 'XY', startAt=0, maxResults=50)
JiraError HTTP 400 url: https://abcd.atlassian.net/rest/api/2/search?jql=project+%3D+%27XY%27&startAt=0&validateQuery=True&fields=%2Aall&maxResults=50
	text: The value 'XY' does not exist for the field 'project'.
	
	response headers = {'Date': 'Tue, 02 Jul 2024 11:37:35 GMT', 'Content-Type': 'application/json;charset=UTF-8', 'Server': 'AtlassianEdge', 'Timing-Allow-Origin': '*', 'X-Arequestid': 'REDACTED', 'X-Aaccountid': 'REDACTED', 'Cache-Control': 'no-cache, no-store, no-transform', 'X-Content-Type-Options': 'nosniff', 'X-Xss-Protection': '1; mode=block', 'Atl-Traceid': 'REDACTED', 'Strict-Transport-Security': 'max-age=63072000; includeSubDomains; preload', 'Report-To': '{"endpoints": [{"url": "https://dy8abcen1416s.cloudfront.net"}], "group": "endpoint-1", "include_subdomains": true, "max_age": 600}', 'Nel': '{"failure_fraction": 0.001, "includpenkvv6s.cloudfront.net"}], "group": "endpoint-1", "include_subdomains": true, "max_age": 600}', 'Nel': '{"failure_fraction": 0.001, "include_subdomains": true, "max_age": 600, "report_to": "endpoint-1"}', 'Transfer-Encoding': 'chunked'}
	response text = {"errorMessages":["The value 'XY' does not exist for the field 'project'."],"warningMessages":[]} client.search_issues(project = 'XY', startAt=0, maxResults=50)
^CTraceback (most recent call last):
  File "/Users/user/tmp/.venv/lib/python3.12/site-packages/n0s1/controllers/jira_controller.py", line 87, in get_data
    issues = self._client.search_issues(ql, startAt=issue_start, maxResults=limit)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/tmp/.venv/lib/python3.12/site-packages/jira/client.py", line 3557, in search_issues
    issues = self._fetch_pages(
             ^^^^^^^^^^^^^^^^^^
  File "/Users/user/tmp/.venv/lib/python3.12/site-packages/jira/client.py", line 817, in _fetch_pages
    resource = self._get_json(
               ^^^^^^^^^^^^^^^
  File "/Users/user/tmp/.venv/lib/python3.12/site-packages/jira/client.py", line 4358, in _get_json
    else self._session.get(url, params=params)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/tmp/.venv/lib/python3.12/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/tmp/.venv/lib/python3.12/site-packages/jira/resilientsession.py", line 247, in request
    elif raise_on_error(response, **processed_kwargs):
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/tmp/.venv/lib/python3.12/site-packages/jira/resilientsession.py", line 72, in raise_on_error
    raise JIRAError(
jira.exceptions.JIRAError: JiraError HTTP 400 url: https://abcd.atlassian.net/rest/api/2/search?jql=project+%3D+%27XY%27&startAt=0&validateQuery=True&fields=%2Aall&maxResults=50
	text: The value 'XY' does not exist for the field 'project'.
	
	response headers = {'Date': 'Tue, 02 Jul 2024 11:37:35 GMT', 'Content-Type': 'application/json;charset=UTF-8', 'Server': 'AtlassianEdge', 'Timing-Allow-Origin': '*', 'X-Arequestid': 'REDACTED', 'X-Aaccountid': 'REDACTED', 'Cache-Control': 'no-cache, no-store, no-transform', 'X-Content-Type-Options': 'nosniff', 'X-Xss-Protection': '1; mode=block', 'Atl-Traceid': 'REDACTED', 'Strict-Transport-Security': 'max-age=63072000; includeSubDomains; preload', 'Report-To': '{"endpoints": [{"url": "https://dy8abcen1416s.cloudfront.net"}], "group": "endpoint-1", "include_subdomains": true, "max_age": 600}', 'Nel': '{"failure_fraction": 0.001, "include_subdomains": true, "max_age": 600, "report_to": "endpoint-1"}', 'Transfer-Encoding': 'chunked'}
	response text = {"errorMessages":["The value 'XY' does not exist for the field 'project'."],"warningMessages":[]}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/user/tmp/.venv/bin/n0s1", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/user/tmp/.venv/lib/python3.12/site-packages/n0s1/n0s1.py", line 631, in main
    scan(regex_config, controller, scan_arguments)
  File "/Users/user/tmp/.venv/lib/python3.12/site-packages/n0s1/n0s1.py", line 410, in scan
    for ticket in controller.get_data(scan_comment, limit):
  File "/Users/user/tmp/.venv/lib/python3.12/site-packages/n0s1/controllers/jira_controller.py", line 92, in get_data
    time.sleep(1)
KeyboardInterrupt

Describe the solution you'd like
Handle the JiraError exception by adding break statement to the while not issues_finished loop to skip to the next project. This will allow the tool to continue scanning other projects even if searching issues in some projects returns a 400 error (see API docs).

Here is my implementation to handle this issue in my case: https://github.com/jarp0l/n0s1/blob/c3e84b5a91310bcae5f178c0a92072f804368f18/src/n0s1/controllers/jira_controller.py#L89-L93

while not issues_finished:
    try:
        issues = self._client.search_issues(ql, startAt=issue_start, maxResults=limit)
    except JIRAError as e:
        self.log_message(f"Error while searching issues on Jira project: [{key}]. Skipping...", logging.ERROR)
        self.log_message(e)
        issues = [{}]
        break

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions