How to use the awokado.exceptions.BaseApiException function in awokado

To help you get started, we’ve selected a few awokado 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 5783354 / awokado / awokado / exceptions / forbidden.py View on Github external
def __init__(self, details="", code="forbidden"):
        BaseApiException.__init__(
            self,
            status=falcon.HTTP_403,
            title=falcon.HTTP_403,
            code=code,
            details=details,
        )
github 5783354 / awokado / awokado / exceptions / not_found.py View on Github external
def __init__(self, details="", code="not-found"):
        BaseApiException.__init__(
            self,
            status=falcon.HTTP_NOT_FOUND,
            title=falcon.HTTP_NOT_FOUND,
            code=code,
            details=details,
        )
github 5783354 / awokado / awokado / exceptions / forbidden.py View on Github external
import falcon

from awokado.exceptions import BaseApiException


class Forbidden(BaseApiException):
    def __init__(self, details="", code="forbidden"):
        BaseApiException.__init__(
            self,
            status=falcon.HTTP_403,
            title=falcon.HTTP_403,
            code=code,
            details=details,
        )


class CreateResourceForbidden(Forbidden):
    def __init__(self, details="The creation of a resource forbidden"):
        Forbidden.__init__(self, code="create-forbidden", details=details)


class UpdateResourceForbidden(Forbidden):
github 5783354 / awokado / awokado / utils.py View on Github external
def api_exception_handler(error, req, resp, params):
    if isinstance(error, BaseApiException):
        resp.status = error.status

        if error.headers is not None:
            resp.set_headers(error.headers)

        if error.has_representation:
            json_error_serializer(req, resp, error)

        if settings.get("AWOKADO_LOG_USERS_EXCEPTIONS", False):
            exc_info = sys.exc_info()
            log.error("User error: ", exc_info=exc_info)

    elif isinstance(error, falcon.HTTPNotFound):
        resp.status = "404 Not Found"
        resp.content_type = "application/json"
        resp.body = json.dumps({"error": f"{req.path} not found"})
github 5783354 / awokado / awokado / exceptions / not_found.py View on Github external
import falcon

from awokado.exceptions import BaseApiException


class NotFound(BaseApiException):
    def __init__(self, details="", code="not-found"):
        BaseApiException.__init__(
            self,
            status=falcon.HTTP_NOT_FOUND,
            title=falcon.HTTP_NOT_FOUND,
            code=code,
            details=details,
        )


class ResourceNotFound(NotFound):
    def __init__(self, resource=None, details=None):
        """
        :type resource: str
        :type details: str
        """