# Path: django_sonic_screwdriver/models.py
# class ErrorCodes(Enum):
#     def __str__(self):
#         return str(self.value)


from django.utils.translation import ugettext_lazy as _
from rest_framework import exceptions, status
from rest_framework.views import set_rollback, Response
from .models import ErrorCodes
        exception = UnauthorizedException()

    # 429 Handler
    if isinstance(exception, exceptions.Throttled):
        exception = TooManyRequestsException()

    if isinstance(exception, exceptions.ValidationError):
        # Convert the inconsistent Django error format into a consistent one.
        all_errors = []
        for key, err_details in exception.get_full_details().items():
            for ed in err_details:
                all_errors.append(
                    {
                        "message": ed["message"],
                        "code": ed["code"].value
                        if isinstance(ed["code"], ErrorCodes)
                        else ed["code"],
                    }
                )

        data["errors"] = all_errors
        data["status"] = exception.status_code

        return Response(status=exception.status_code, data=data)

    if isinstance(exception, exceptions.APIException):
        headers = {}

        if getattr(exception, "auth_header", None):
            headers["WWW-Authenticate"] = exception.auth_header

# Path: django_sonic_screwdriver/models.py
# class ErrorCodes(Enum):
#     def __str__(self):
#         return str(self.value)


# Path: django_sonic_screwdriver/exceptions.py
from django.utils.translation import ugettext_lazy as _
from rest_framework import exceptions, status
from rest_framework.views import set_rollback, Response
from .models import ErrorCodes

        exception = UnauthorizedException()

    # 429 Handler
    if isinstance(exception, exceptions.Throttled):
        exception = TooManyRequestsException()

    if isinstance(exception, exceptions.ValidationError):
        # Convert the inconsistent Django error format into a consistent one.
        all_errors = []
        for key, err_details in exception.get_full_details().items():
            for ed in err_details:
                all_errors.append(
                    {
                        "message": ed["message"],
                        "code": ed["code"].value
                        if isinstance(ed["code"], ErrorCodes)
                        else ed["code"],
                    }
                )

        data["errors"] = all_errors
        data["status"] = exception.status_code

        return Response(status=exception.status_code, data=data)

    if isinstance(exception, exceptions.APIException):
        headers = {}

        if getattr(exception, "auth_header", None):
            headers["WWW-Authenticate"] = exception.auth_header

        if getattr(exception, "wait", None):