from rest_framework.exceptions import APIException
from rest_framework.exceptions import PermissionDenied as RestFrameworkPermissionDenied

class XOSProgrammingError(APIException):
    status_code=400
    def __init__(self, why="programming error", fields={}):
        APIException.__init__(self, {"error": "XOSProgrammingError",
                            "specific_error": why,
                            "fields": fields})

class XOSPermissionDenied(RestFrameworkPermissionDenied):
    def __init__(self, why="permission error", fields={}):
        APIException.__init__(self, {"error": "XOSPermissionDenied",
                            "specific_error": why,
                            "fields": fields})

class XOSNotAuthenticated(RestFrameworkPermissionDenied):
    def __init__(self, why="you must be authenticated to use this api", fields={}):
        APIException.__init__(self, {"error": "XOSNotAuthenticated",
                            "specific_error": why,
                            "fields": fields})

class XOSNotFound(RestFrameworkPermissionDenied):
    status_code=404
    def __init__(self, why="object not found", fields={}):
        APIException.__init__(self, {"error": "XOSNotFound",
                            "specific_error": why,
                            "fields": fields})

class XOSValidationError(APIException):
    status_code=403
    def __init__(self, why="validation error", fields={}):
        APIException.__init__(self, {"error": "XOSValidationError",
                            "specific_error": why,
                            "fields": fields})

class XOSDuplicateKey(APIException):
    status_code=400
    def __init__(self, why="duplicate key", fields={}):
        APIException.__init__(self, {"error": "XOSDuplicateKey",
                            "specific_error": why,
                            "fields": fields})

class XOSMissingField(APIException):
    status_code=400
    def __init__(self, why="missing field", fields={}):
        APIException.__init__(self, {"error": "XOSMissingField",
                            "specific_error": why,
                            "fields": fields})

class XOSConfigurationError(APIException):
    status_code=400
    def __init__(self, why="configuration error", fields={}):
        APIException.__init__(self, {"error": "XOSConfigurationError",
                            "specific_error": why,
                            "fields": fields})

@@ -2420,28 +2420,313 @@
          %22fields%22: fields%7D)%0A
+%0Aclass XOSConflictingField(APIException):%0A    status_code=400%0A    def __init__(self, why=%22conflicting field%22, fields=%7B%7D):%0A        APIException.__init__(self, %7B%22error%22: %22XOSMissingField%22,%0A                            %22specific_error%22: why,%0A                            %22fields%22: fields%7D)%0A

add XOSConflictingField exception