コンテンツにスキップ

error

DEFAULT_BASIC_AUTH_HEADER_NOT_FOUND_ERROR

The default error raised when the header Authorization is not found for basic authentication. The status to be returned to the client is 401.

DEFAULT_BEARER_AUTH_HEADER_NOT_FOUND_ERROR

The default error raised when the header Authorization is not found for bearer authentication. The status to be returned to the client is 401.

DEFAULT_CORS_ERROR

The default error raised when an origin doesn't allowed to access the endpoint within the CORS sessions.

DEFAULT_HEADER_NOT_FOUND_ERROR

The default error raised when a request doesn't have the header promised by server side. The status to be returned to the client is 400.

DEFAULT_NOT_APPLICABLE_IP_ERROR

The default error raised when a forbidden client IP is found. The status to be returned to the client is 415.

DEFAULT_NOT_FOUND_ERROR

The default error of the status 404.

DEFAULT_QUERY_PARAM_NOT_FOUND_ERROR

The default error raised when a request doesn't have the query parameter promised by server side. The status to be returned to the client is 400.

DEFUALT_INCORRECT_DATA_FORMAT_ERROR

The default error of the status 415.

ApiErrInfo

ErrInfo to handle API error.

This ErrInfo has implemented method of 'get_body'. This class emits Json data including error information defined by developer when the error is sent.

dev_message: Optional[str]

Message to explain developers the error.

encoding: str

Encoding to encode response body.

info: Optional[str]

Information about the error.

inheritted_headers: Set[str]

Header names to be inheritted.

user_message: Optional[str]

Message to explain end users the error.

get_body(self)

Publishes response body for error response.

Returns

bytes Response body

Source code in bamboo/error.py
def get_body(self) -> t.Optional[bytes]:
    """Publishes response body for error response.

    Returns
    -------
    bytes
        Response body
    """
    body = {
        "code": self.code,
        "developerMessage": self.dev_message,
        "uesrMessage": self.user_message,
        "info": self.info
    }
    return json.dumps(body).encode(encoding=self.encoding)

DefaultAuthHeaderNotFoundErrInfo

http_status: HTTPStatus

HTTP status of the error.

inheritted_headers: Set[str]

Header names to be inheritted.

get_headers(self)

Publishes additional headers for error response.

Returns:

Type Description
List[Tuple[str, str]]

Additional headers.

Source code in bamboo/error.py
def get_headers(self) -> t.List[t.Tuple[str, str]]:
    value = get_default_auth_realm(self._scheme)
    return [(_WWW_AUTH_HEADER, value)]

DefaultDataFormatErrInfo

http_status: HTTPStatus

HTTP status of the error.

inheritted_headers: Set[str]

Header names to be inheritted.

DefaultHeaderNotFoundErrInfo

http_status: HTTPStatus

HTTP status of the error.

inheritted_headers: Set[str]

Header names to be inheritted.

DefaultNotApplicableIpErrInfo

http_status: HTTPStatus

HTTP status of the error.

inheritted_headers: Set[str]

Header names to be inheritted.

DefaultNotFoundErrInfo

http_status: HTTPStatus

HTTP status of the error.

inheritted_headers: Set[str]

Header names to be inheritted.

DefaultQueryParamNotFoundErrInfo

http_status: HTTPStatus

HTTP status of the error.

inheritted_headers: Set[str]

Header names to be inheritted.

DefualtCORSOriginNotAllowedErrInfo

http_status: HTTPStatus

HTTP status of the error.

inheritted_headers: Set[str]

Header names to be inheritted.

ErrInfo

Base class of all error handlings.

This class defines the attributes of all classes for error handling.

http_status: HTTPStatus

HTTP status of the error.

inheritted_headers: Set[str]

Header names to be inheritted.

__init_subclass__() classmethod special

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

Source code in bamboo/error.py
def __init_subclass__(cls) -> None:
    # Make header names lower to ignore the difference of upper and
    # lower charactors.
    cls.inheritted_headers = set(map(str.lower, cls.inheritted_headers))

get_all_form(self)

Get status code, headers and body of repsponse of the error.

Returns:

Type Description
Tuple[bamboo.http.HTTPStatus, List[Tuple[str, str]], Union[bytes, Iterable[bytes]]]

Tuple of status code, headers and body of the error.

Source code in bamboo/error.py
def get_all_form(
    self,
) -> t.Tuple[
    HTTPStatus,
    t.List[t.Tuple[str, str]],
    t.Union[bytes, t.Iterable[bytes]]
]:
    """Get status code, headers and body of repsponse of the error.

    Returns:
        Tuple of status code, headers and body of the error.
    """
    stat = self.http_status
    headers = self.get_headers()
    body = self.get_body()

    # NOTE
    #   Automatically Content-Type header is to be added.
    headers.append(self.__content_type__.to_header())
    return (stat, headers, BufferedConcatIterator(body))

get_body(self)

Publishes response body for error response.

If one want to send a costom response body, one can freely override the method and return the binary.

Returns Response body of the error.

Source code in bamboo/error.py
def get_body(self) -> t.Union[bytes, t.Iterable[bytes]]:
    """Publishes response body for error response.

    If one want to send a costom response body, one can freely
    override the method and return the binary.

    Returns
        Response body of the error.
    """
    return b""

get_headers(self)

Publishes additional headers for error response.

Returns:

Type Description
List[Tuple[str, str]]

Additional headers.

Source code in bamboo/error.py
def get_headers(self) -> t.List[t.Tuple[str, str]]:
    """Publishes additional headers for error response.

    Returns:
        Additional headers.
    """
    return []

inherit_header(self, header_name)

Make the given header will be inheritted from the endpoint.

This method register the header name as a condidate to be inheritted from the endpoint's response headers. Note that the given header could not be inheritted if the endpoint don't have the corresponding response header, even if the method is called.

Parameters:

Name Type Description Default
header_name str

Header name to be inheritted.

required
Source code in bamboo/error.py
def inherit_header(self, header_name: str) -> None:
    """Make the given header will be inheritted from the endpoint.

    This method register the header name as a condidate to be inheritted
    from the endpoint's response headers. Note that the given header
    could not be inheritted if the endpoint don't have the corresponding
    response header, even if the method is called.

    Args:
        header_name: Header name to be inheritted.
    """
    self.inheritted_headers.add(header_name.lower())

should_inherit_header(header_name) classmethod

Check if the given header will be inheritted or not.

Parameters:

Name Type Description Default
header_name str

Header name to be checked.

required

Returns:

Type Description
bool

True if the given header will be inheritted, otherwise False.

Source code in bamboo/error.py
@classmethod
def should_inherit_header(cls, header_name: str) -> bool:
    """Check if the given header will be inheritted or not.

    Args:
        header_name: Header name to be checked.

    Returns:
        `True` if the given header will be inheritted, otherwise `False`.
    """
    return header_name.lower() in cls.inheritted_headers
Back to top