Source code for rt.exceptions

"""Exceptions collection for the rt library."""

import typing


[docs] class RtError(Exception): """Super class of all Rt Errors."""
[docs] class AuthorizationError(RtError): """Exception raised when module cannot access :term:`API` due to invalid or missing credentials."""
[docs] class NotAllowedError(RtError): """Exception raised when request cannot be finished due to insufficient privileges."""
[docs] class UnexpectedResponseError(RtError): """Exception raised when unexpected HTTP code is received."""
[docs] def __init__(self, message: str, status_code: typing.Optional[int] = None, response_message: typing.Optional[str] = None) -> None: """Initialization.""" super().__init__(message) self.status_code = status_code self.response_message = response_message
[docs] class UnexpectedMessageFormatError(RtError): """Exception raised when response has bad status code (not the HTTP code, but code in the first line of the body as 200 in `RT/4.0.7 200 Ok`) or message parsing fails because of unexpected format. """
[docs] class NotFoundError(RtError): """Exception raised if requested resource is not found."""
[docs] class APISyntaxError(RtError): """Exception raised when syntax error is received."""
[docs] class InvalidUseError(RtError): """Exception raised when API method is not used correctly."""
[docs] class BadRequestError(RtError): """Exception raised when HTTP code 400 (Bad Request) is received."""
[docs] class ConnectionError(RtError): """Encapsulation of various exceptions indicating network problems."""
[docs] def __init__(self, message: str, cause: Exception) -> None: """Initialization of exception extended by cause parameter. :keyword message: Exception details :keyword cause: Cause exception """ super().__init__(f'{message} (Caused by {repr(cause)})') self.cause = cause
[docs] class InvalidQueryError(RtError): """Exception raised when attempting to search RT with an invalid raw query."""