from rest_framework.exceptions import APIException def my_view(request): raise APIException("There was a problem!")