How to use the restless.exceptions.HttpError function in restless

To help you get started, we’ve selected a few restless examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github toastdriven / restless / tests / test_resources.py View on Github external
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.
github toastdriven / restless / restless / exceptions.py View on Github external
# 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
github toastdriven / restless / restless / exceptions.py View on Github external
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
github toastdriven / restless / restless / exceptions.py View on Github external
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
github toastdriven / restless / restless / exceptions.py View on Github external
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
github toastdriven / restless / restless / exceptions.py View on Github external
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."
github toastdriven / restless / restless / exceptions.py View on Github external
def __init__(self, msg=None):
        if not msg:
            msg = self.__class__.msg

        super(HttpError, self).__init__(msg)
github toastdriven / restless / restless / exceptions.py View on Github external
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
github toastdriven / restless / restless / exceptions.py View on Github external
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):
github toastdriven / restless / restless / exceptions.py View on Github external
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