Represents a single error returned from Reddit's API.
| 109 | |
| 110 | |
| 111 | class RedditErrorItem: |
| 112 | """Represents a single error returned from Reddit's API.""" |
| 113 | |
| 114 | @property |
| 115 | def error_message(self) -> str: |
| 116 | """The completed error message string.""" |
| 117 | error_str = self.error_type |
| 118 | if self.message: |
| 119 | error_str += f": {self.message!r}" |
| 120 | if self.field: |
| 121 | error_str += f" on field {self.field!r}" |
| 122 | return error_str |
| 123 | |
| 124 | def __eq__(self, other: object) -> bool: |
| 125 | """Check for equality.""" |
| 126 | if isinstance(other, RedditErrorItem): |
| 127 | return (self.error_type, self.message, self.field) == ( |
| 128 | other.error_type, |
| 129 | other.message, |
| 130 | other.field, |
| 131 | ) |
| 132 | return super().__eq__(other) |
| 133 | |
| 134 | def __hash__(self) -> int: |
| 135 | """Return the hash of the current instance.""" |
| 136 | return hash(self.__class__.__name__) ^ hash((self.error_type, self.message, self.field)) |
| 137 | |
| 138 | def __init__( |
| 139 | self, |
| 140 | error_type: str, |
| 141 | *, |
| 142 | field: str | None = None, |
| 143 | message: str | None = None, |
| 144 | ) -> None: |
| 145 | """Initialize a :class:`.RedditErrorItem` instance. |
| 146 | |
| 147 | :param error_type: The error type set on Reddit's end. |
| 148 | :param field: The input field associated with the error, if available. |
| 149 | :param message: The associated message for the error. |
| 150 | |
| 151 | """ |
| 152 | self.error_type = error_type |
| 153 | self.message = message |
| 154 | self.field = field |
| 155 | |
| 156 | def __repr__(self) -> str: |
| 157 | """Return an object initialization representation of the instance.""" |
| 158 | return ( |
| 159 | f"{self.__class__.__name__}(error_type={self.error_type!r}, message={self.message!r}, field={self.field!r})" |
| 160 | ) |
| 161 | |
| 162 | def __str__(self) -> str: |
| 163 | """Get the message returned from str(self).""" |
| 164 | return self.error_message |
| 165 | |
| 166 | |
| 167 | class TooLargeMediaException(ClientException): |
no outgoing calls
searching dependent graphs…