Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_build_error(self):
err = HttpError("Whoopsie")
resp = self.res.build_error(err)
resp_body = json.loads(resp.body)
self.assertEqual(resp_body, {'error': 'Whoopsie'})
self.assertEqual(resp.content_type, 'application/json')
self.assertEqual(resp.status_code, 500)
nf_err = NotFound()
resp = self.res.build_error(nf_err)
resp_body = json.loads(resp.body)
# Default error message.
self.assertEqual(resp_body, {'error': 'Resource not found.'})
self.assertEqual(resp.content_type, 'application/json')
# Custom status code.
self.assertEqual(resp.status_code, 404)
# Non-restless exception.
# TODO: make serializers handle it?
status = NOT_ACCEPTABLE
msg = "Unable to send content specified on the request's Accept header(s)."
class Conflict(HttpError):
status = CONFLICT
msg = "There was a conflict when processing the request."
class Gone(HttpError):
status = GONE
msg = "Resource removed permanently."
class PreconditionFailed(HttpError):
status = PRECONDITION_FAILED
msg = "Unable to satisfy one or more request preconditions."
class UnsupportedMediaType(HttpError):
status = UNSUPPORTED_MEDIA_TYPE
msg = "Type of media provided on request is not supported."
class ExpectationFailed(HttpError):
status = EXPECTATION_FAILED
msg = "Unable to satisfy requirements of Expect header."
class IAmATeapot(HttpError):
status = I_AM_A_TEAPOT
class IAmATeapot(HttpError):
status = I_AM_A_TEAPOT
msg = "This is a teapot; do not attempt to brew coffee with it."
class UnprocessableEntity(HttpError):
status = UNPROCESSABLE_ENTITY
msg = "Request cannot be followed due to a semantic error."
class Locked(HttpError):
status = LOCKED
msg = "Resource is locked."
class FailedDependency(HttpError):
status = FAILED_DEPENDENCY
msg = "Request failed due to a previous failed request."
class TooManyRequests(HttpError):
status = TOO_MANY_REQUESTS
msg = "There was a conflict when processing the request."
class UnavailableForLegalReasons(HttpError):
status = UNAVAILABLE_FOR_LEGAL_REASONS
msg = "Resource made unavailable by a legal decision."
class MethodNotImplemented(HttpError):
status = METHOD_NOT_IMPLEMENTED
class Conflict(HttpError):
status = CONFLICT
msg = "There was a conflict when processing the request."
class Gone(HttpError):
status = GONE
msg = "Resource removed permanently."
class PreconditionFailed(HttpError):
status = PRECONDITION_FAILED
msg = "Unable to satisfy one or more request preconditions."
class UnsupportedMediaType(HttpError):
status = UNSUPPORTED_MEDIA_TYPE
msg = "Type of media provided on request is not supported."
class ExpectationFailed(HttpError):
status = EXPECTATION_FAILED
msg = "Unable to satisfy requirements of Expect header."
class IAmATeapot(HttpError):
status = I_AM_A_TEAPOT
msg = "This is a teapot; do not attempt to brew coffee with it."
class UnprocessableEntity(HttpError):
status = UNPROCESSABLE_ENTITY
class PreconditionFailed(HttpError):
status = PRECONDITION_FAILED
msg = "Unable to satisfy one or more request preconditions."
class UnsupportedMediaType(HttpError):
status = UNSUPPORTED_MEDIA_TYPE
msg = "Type of media provided on request is not supported."
class ExpectationFailed(HttpError):
status = EXPECTATION_FAILED
msg = "Unable to satisfy requirements of Expect header."
class IAmATeapot(HttpError):
status = I_AM_A_TEAPOT
msg = "This is a teapot; do not attempt to brew coffee with it."
class UnprocessableEntity(HttpError):
status = UNPROCESSABLE_ENTITY
msg = "Request cannot be followed due to a semantic error."
class Locked(HttpError):
status = LOCKED
msg = "Resource is locked."
class FailedDependency(HttpError):
status = FAILED_DEPENDENCY
class Locked(HttpError):
status = LOCKED
msg = "Resource is locked."
class FailedDependency(HttpError):
status = FAILED_DEPENDENCY
msg = "Request failed due to a previous failed request."
class TooManyRequests(HttpError):
status = TOO_MANY_REQUESTS
msg = "There was a conflict when processing the request."
class UnavailableForLegalReasons(HttpError):
status = UNAVAILABLE_FOR_LEGAL_REASONS
msg = "Resource made unavailable by a legal decision."
class MethodNotImplemented(HttpError):
status = METHOD_NOT_IMPLEMENTED
msg = "The specified HTTP method is not implemented."
class Unavailable(HttpError):
status = UNAVAILABLE
msg = "There was a conflict when processing the request."
def __init__(self, msg=None):
if not msg:
msg = self.__class__.msg
super(HttpError, self).__init__(msg)
class Gone(HttpError):
status = GONE
msg = "Resource removed permanently."
class PreconditionFailed(HttpError):
status = PRECONDITION_FAILED
msg = "Unable to satisfy one or more request preconditions."
class UnsupportedMediaType(HttpError):
status = UNSUPPORTED_MEDIA_TYPE
msg = "Type of media provided on request is not supported."
class ExpectationFailed(HttpError):
status = EXPECTATION_FAILED
msg = "Unable to satisfy requirements of Expect header."
class IAmATeapot(HttpError):
status = I_AM_A_TEAPOT
msg = "This is a teapot; do not attempt to brew coffee with it."
class UnprocessableEntity(HttpError):
status = UNPROCESSABLE_ENTITY
msg = "Request cannot be followed due to a semantic error."
class Locked(HttpError):
status = LOCKED
class BadRequest(HttpError):
status = BAD_REQUEST
msg = "Bad request."
class Unauthorized(HttpError):
status = UNAUTHORIZED
msg = "Unauthorized."
class Forbidden(HttpError):
status = FORBIDDEN
msg = "Permission denied."
class NotFound(HttpError):
status = NOT_FOUND
msg = "Resource not found."
class MethodNotAllowed(HttpError):
status = METHOD_NOT_ALLOWED
msg = "The specified HTTP method is not allowed."
class NotAcceptable(HttpError):
# TODO: make serializers handle it?
status = NOT_ACCEPTABLE
msg = "Unable to send content specified on the request's Accept header(s)."
class Conflict(HttpError):
status = METHOD_NOT_ALLOWED
msg = "The specified HTTP method is not allowed."
class NotAcceptable(HttpError):
# TODO: make serializers handle it?
status = NOT_ACCEPTABLE
msg = "Unable to send content specified on the request's Accept header(s)."
class Conflict(HttpError):
status = CONFLICT
msg = "There was a conflict when processing the request."
class Gone(HttpError):
status = GONE
msg = "Resource removed permanently."
class PreconditionFailed(HttpError):
status = PRECONDITION_FAILED
msg = "Unable to satisfy one or more request preconditions."
class UnsupportedMediaType(HttpError):
status = UNSUPPORTED_MEDIA_TYPE
msg = "Type of media provided on request is not supported."
class ExpectationFailed(HttpError):
status = EXPECTATION_FAILED