From 57936073dbd780943d03b5aadcd86e9512851c32 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 4 Jul 2025 17:57:08 +0930 Subject: [PATCH] feat(api): map notfound and perm denied django -> drf exceptions ref: #849 --- app/api/viewsets/common.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/api/viewsets/common.py b/app/api/viewsets/common.py index 2c2e153f..2bffe5f4 100644 --- a/app/api/viewsets/common.py +++ b/app/api/viewsets/common.py @@ -418,17 +418,31 @@ class CommonViewSet( rtn_exception = None - if isinstance(exc, django.core.exceptions.ValidationError): + if isinstance(exc, django.core.exceptions.ObjectDoesNotExist): - try: + exc = rest_framework.exceptions.NotFound(exc.args) - raise rest_framework.exceptions.ValidationError(exc.error_dict) + elif isinstance(exc, django.core.exceptions.PermissionDenied): - except Exception as e: - return e + exc = rest_framework.exceptions.PermissionDenied(exc.error_dict) - raise ValueError('20250704-Unknown Exception Type. Unable to convert. Please report this error as a bug.') + elif isinstance(exc, django.core.exceptions.ValidationError): + + + exc = rest_framework.exceptions.ValidationError(exc.error_dict) + + else: + + exc = ValueError('20250704-Unknown Exception Type. Unable to convert. Please report this error as a bug.') + + try: + + raise exc + + except Exception as e: + + return e