Skip to content

Commit

Permalink
Fixed invalid api key format raising 500 (#1079)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
3 people authored Jan 28, 2025
1 parent df47b4a commit 2825062
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion backend/api_v2/key_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2825062

Please sign in to comment.