Browse Source

Merge pull request #1999 from doccano/enhancement/handleJSONDecodeError

Handle JSONDecodeError on testing auto labeling API
pull/2000/head
Hiroki Nakayama 2 years ago
committed by GitHub
parent
commit
f3f8747ab9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions
  1. 4
      backend/auto_labeling/exceptions.py
  2. 3
      backend/auto_labeling/views.py

4
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."

3
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

Loading…
Cancel
Save