From 28250629742683311f3d33822ce825ccc5c9eb80 Mon Sep 17 00:00:00 2001 From: Praveen Kumar Date: Tue, 28 Jan 2025 12:26:23 +0530 Subject: [PATCH] Fixed invalid api key format raising 500 (#1079) * Fixed invalid api key format raising 500 * Modified the validate_api_key method to capture validation error and raise a UnauthorizedKey() error * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Gayathri <142381512+gaya3-zipstack@users.noreply.github.com> --- backend/api_v2/key_helper.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/api_v2/key_helper.py b/backend/api_v2/key_helper.py index 2ff10654c..22421ff86 100644 --- a/backend/api_v2/key_helper.py +++ b/backend/api_v2/key_helper.py @@ -4,6 +4,7 @@ from api_v2.exceptions import UnauthorizedKey from api_v2.models import APIDeployment, APIKey from api_v2.serializers import APIKeySerializer +from django.core.exceptions import ValidationError from pipeline_v2.models import Pipeline from rest_framework.request import Request from workflow_manager.workflow_v2.workflow_helper import WorkflowHelper @@ -29,7 +30,7 @@ def validate_api_key( api_key_instance: APIKey = APIKey.objects.get(api_key=api_key) if not KeyHelper.has_access(api_key_instance, instance): raise UnauthorizedKey() - except APIKey.DoesNotExist: + except (APIKey.DoesNotExist, ValidationError): raise UnauthorizedKey() @staticmethod