tomaae.homeassistant-mikrot.../custom_components/mikrotik_router/librouteros_custom/exceptions.py

53 lines
1.2 KiB
Python
Raw Normal View History

# -*- coding: UTF-8 -*-
class LibRouterosError(Exception):
"""Base exception for all other."""
class ConnectionClosed(LibRouterosError):
"""Raised when connection have been closed."""
class ProtocolError(LibRouterosError):
"""Raised when e.g. encoding/decoding fails."""
class FatalError(ProtocolError):
"""Exception raised when !fatal is received."""
class TrapError(ProtocolError):
"""
Exception raised when !trap is received.
:param int category: Optional integer representing category.
:param str message: Error message.
"""
def __init__(self, message, category=None):
self.category = category
self.message = message
super().__init__()
def __str__(self):
return str(self.message.replace('\r\n', ','))
def __repr__(self):
return '{}({!r})'.format(self.__class__.__name__, str(self))
class MultiTrapError(ProtocolError):
"""
Exception raised when multiple !trap words have been received in one response.
:param traps: TrapError instances.
"""
def __init__(self, *traps):
self.traps = traps
super().__init__()
def __str__(self):
return ', '.join(str(trap) for trap in self.traps)