diff --git a/rest_framework_yaml/compat.py b/rest_framework_yaml/compat.py index 9f6c147..2e5efc0 100644 --- a/rest_framework_yaml/compat.py +++ b/rest_framework_yaml/compat.py @@ -36,3 +36,9 @@ except ImportError: ReturnDict = None ReturnList = None + +try: + # Note: ErrorDetail was introduced in DRF 3.5.0 + from rest_framework.exceptions import ErrorDetail +except ImportError: + ErrorDetail = None diff --git a/rest_framework_yaml/encoders.py b/rest_framework_yaml/encoders.py index a69dc70..848ae19 100644 --- a/rest_framework_yaml/encoders.py +++ b/rest_framework_yaml/encoders.py @@ -2,13 +2,14 @@ Helper classes for parsers. """ from __future__ import unicode_literals + import decimal import types from django.utils import six from .compat import ( - yaml, yaml_represent_text, Hyperlink, OrderedDict, ReturnDict, ReturnList + yaml, yaml_represent_text, Hyperlink, OrderedDict, ReturnDict, ReturnList, ErrorDetail ) @@ -80,3 +81,9 @@ def represent_mapping(self, tag, mapping, flow_style=None): ReturnList, yaml.representer.SafeRepresenter.represent_list ) + +if ErrorDetail: + SafeDumper.add_representer( + ErrorDetail, + yaml_represent_text + )