A wrapper class for error messages. Use this to wrap error messages that should be distinguishable from normal responses. Example: >>> error = ErrorBox("Connection failed") >>> if ErrorBox.is_error_box(error): ... print(f"Error: {error}")
| 7 | |
| 8 | |
| 9 | class ErrorBox: |
| 10 | """ |
| 11 | A wrapper class for error messages. |
| 12 | |
| 13 | Use this to wrap error messages that should be distinguishable from normal responses. |
| 14 | |
| 15 | Example: |
| 16 | >>> error = ErrorBox("Connection failed") |
| 17 | >>> if ErrorBox.is_error_box(error): |
| 18 | ... print(f"Error: {error}") |
| 19 | """ |
| 20 | |
| 21 | def __init__(self, error_msg: str) -> None: |
| 22 | self.error_msg = error_msg |
| 23 | |
| 24 | def __str__(self) -> str: |
| 25 | return self.error_msg |
| 26 | |
| 27 | def __repr__(self) -> str: |
| 28 | return f"ErrorBox({self.error_msg!r})" |
| 29 | |
| 30 | @staticmethod |
| 31 | def is_error_box(something: Any) -> bool: |
| 32 | """Check if the given object is an ErrorBox instance.""" |
| 33 | return isinstance(something, ErrorBox) |
| 34 | |
| 35 | |
| 36 | class ResponseBox: |
nothing calls this directly
no outgoing calls
no test coverage detected