From 348ef951c64de27f3cc81115e7c95beab62ef65e Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 13 Oct 2022 09:07:21 +0800 Subject: [PATCH] =?UTF-8?q?django=20validationerr=20=E5=8A=A0=E5=88=B0=20u?= =?UTF-8?q?til=20exception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/utils/exceptions.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/utils/exceptions.py b/apps/utils/exceptions.py index 262d9787..83413913 100755 --- a/apps/utils/exceptions.py +++ b/apps/utils/exceptions.py @@ -1,6 +1,6 @@ import traceback -from django.core.exceptions import PermissionDenied +from django.core.exceptions import PermissionDenied, ValidationError from django.http import Http404 import logging from rest_framework import exceptions @@ -21,6 +21,8 @@ def custom_exception_hander(exc, context): exc = exceptions.NotFound() elif isinstance(exc, PermissionDenied): exc = exceptions.PermissionDenied() + elif isinstance(exc, ValidationError): + exc = exceptions.ValidationError(exc.message) request_id = getattr(context['request'], 'request_id', None) if isinstance(exc, exceptions.APIException):