Source code for lol.exceptions
class HTTPCodeException(Exception):
code = 0
default_message = ""
[docs]class BadRequest(HTTPCodeException):
"""Raised when a bad request was sent.
Attributes:
code (:class:`int`): The HTTP code of the error.
message (:class:`str`): The message associated with the error.
"""
code = 400
default_message = "Bad request."
[docs]class Unauthorized(HTTPCodeException):
"""Raised when you are unauthorized to perform an action.
Attributes:
code (:class:`int`): The HTTP code of the error.
message (:class:`str`): The message associated with the error.
"""
code = 401
default_message = "You are unauthorized for this action."
[docs]class Forbidden(HTTPCodeException):
"""Raised when you are forbidden to perform an action.
This may also be raised when your token is invalid.
Attributes:
code (:class:`int`): The HTTP code of the error.
message (:class:`str`): The message associated with the error.
"""
code = 403
default_message = "You are forbidden. (Hint: Your token may be incorrect)"
[docs]class DataNotFound(HTTPCodeException):
"""Raised when the requested data could not be found/does not exist.
Attributes:
code (:class:`int`): The HTTP code of the error.
message (:class:`str`): The message associated with the error.
"""
code = 404
default_message = "Data not found."
[docs]class MethodNotAllowed(HTTPCodeException):
"""Raised when the request's method isn't allowed for that endpoint.
Attributes:
code (:class:`int`): The HTTP code of the error.
message (:class:`str`): The message associated with the error.
"""
code = 405
default_message = "Method not allowed."
[docs]class UnsupportedMediaType(HTTPCodeException):
"""Raised when that media type is unsupported for that endpoint.
Attributes:
code (:class:`int`): The HTTP code of the error.
message (:class:`str`): The message associated with the error.
"""
code = 415
default_message = "Unsupported media type."
[docs]class RateLimitExceeded(HTTPCodeException):
"""Raised when you have exceeded the rate limit.
Attributes:
code (:class:`int`): The HTTP code of the error.
message (:class:`str`): The message associated with the error.
"""
code = 429
default_message = "You have exceeded the rate limit."
[docs]class InternalServerError(HTTPCodeException):
"""Raised when the remote server incurred an error processing your request.
Attributes:
code (:class:`int`): The HTTP code of the error.
message (:class:`str`): The message associated with the error.
"""
code = 500
default_message = "Internal server error."
[docs]class BadGateway(HTTPCodeException):
"""Raised when there is a problem with the gateway.
Attributes:
code (:class:`int`): The HTTP code of the error.
message (:class:`str`): The message associated with the error.
"""
code = 502
default_message = "Bad gateway."
[docs]class GatewayTimeout(HTTPCodeException):
"""Raised when the gateway times out.
Attributes:
code (:class:`int`): The HTTP code of the error.
message (:class:`str`): The message associated with the error.
"""
code = 504
default_message = "Gateway timed out."
_all_code_exceptions = [BadRequest, Unauthorized, Forbidden,
DataNotFound, MethodNotAllowed, UnsupportedMediaType,
RateLimitExceeded, InternalServerError, BadGateway,
ServiceUnavailable, GatewayTimeout]
def exception_from_code(code: int):
for exception in _all_code_exceptions:
if exception.code == code:
return exception
return None
class ClientSessionNotCreated(Exception):
pass