From cd69b06e5e826b0b7487beb5bacd22a666171924 Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Thu, 13 Apr 2023 00:34:53 +0530 Subject: [PATCH] fix: error message for jira importers (#794) --- apiserver/plane/api/views/importer.py | 40 +++++++++++++++------------ 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/apiserver/plane/api/views/importer.py b/apiserver/plane/api/views/importer.py index a0ced0dc7..a51af9c22 100644 --- a/apiserver/plane/api/views/importer.py +++ b/apiserver/plane/api/views/importer.py @@ -65,29 +65,35 @@ class ServiceIssueImportSummaryEndpoint(BaseAPIView): ) if service == "jira": + # Check for all the keys + params = { + "project_key": "Project key is required", + "api_token": "API token is required", + "email": "Email is required", + "cloud_hostname": "Cloud hostname is required", + } + + for key, error_message in params.items(): + if not request.GET.get(key, False): + return Response( + {"error": error_message}, status=status.HTTP_400_BAD_REQUEST + ) + project_key = request.GET.get("project_key", "") api_token = request.GET.get("api_token", "") email = request.GET.get("email", "") cloud_hostname = request.GET.get("cloud_hostname", "") - if ( - not bool(project_key) - or not bool(api_token) - or not bool(email) - or not bool(cloud_hostname) - ): - return Response( - { - "error": "Project name, Project key, API token, Cloud hostname and email are requied" - }, - status=status.HTTP_400_BAD_REQUEST, - ) - return Response( - jira_project_issue_summary( - email, api_token, project_key, cloud_hostname - ), - status=status.HTTP_200_OK, + response = jira_project_issue_summary( + email, api_token, project_key, cloud_hostname ) + if "error" in response: + return Response(response, status=status.HTTP_400_BAD_REQUEST) + else: + return Response( + response, + status=status.HTTP_200_OK, + ) return Response( {"error": "Service not supported yet"}, status=status.HTTP_400_BAD_REQUEST,