diff --git a/backend/auto_labeling/exceptions.py b/backend/auto_labeling/exceptions.py index 8b94890b..a6368e4c 100644 --- a/backend/auto_labeling/exceptions.py +++ b/backend/auto_labeling/exceptions.py @@ -24,3 +24,7 @@ class SampleDataException(ValidationError): class TemplateMappingError(ValidationError): default_detail = "The response cannot be mapped. You might need to change the template." + + +class ResponseJSONDecodeError(ValidationError): + default_detail = "The response cannot be decoded." "Please try to return the response in dictionary or list format." diff --git a/backend/auto_labeling/views.py b/backend/auto_labeling/views.py index aa092611..43dfad92 100644 --- a/backend/auto_labeling/views.py +++ b/backend/auto_labeling/views.py @@ -17,6 +17,7 @@ from rest_framework.views import APIView from .exceptions import ( AWSTokenError, + ResponseJSONDecodeError, SampleDataException, TemplateMappingError, URLConnectionError, @@ -94,6 +95,8 @@ class RestAPIRequestTesting(APIView): raise URLConnectionError except botocore.exceptions.ClientError: raise AWSTokenError() + except json.decoder.JSONDecodeError: + raise ResponseJSONDecodeError() except Exception as e: raise e