|
10 | 10 |
|
11 | 11 |
|
12 | 12 | __all__ = ('PostgresError', 'FatalPostgresError', 'UnknownPostgresError',
|
13 |
| - 'InterfaceError', 'PostgresLogMessage') |
| 13 | + 'InterfaceError', 'InterfaceWarning', 'PostgresLogMessage') |
14 | 14 |
|
15 | 15 |
|
16 | 16 | def _is_asyncpg_class(cls):
|
@@ -159,9 +159,36 @@ class UnknownPostgresError(FatalPostgresError):
|
159 | 159 | """An error with an unknown SQLSTATE code."""
|
160 | 160 |
|
161 | 161 |
|
162 |
| -class InterfaceError(Exception): |
| 162 | +class InterfaceMessage: |
| 163 | + def __init__(self, *, detail=None, hint=None): |
| 164 | + self.detail = detail |
| 165 | + self.hint = hint |
| 166 | + |
| 167 | + def __str__(self): |
| 168 | + msg = self.args[0] |
| 169 | + if self.detail: |
| 170 | + msg += '\nDETAIL: {}'.format(self.detail) |
| 171 | + if self.hint: |
| 172 | + msg += '\nHINT: {}'.format(self.hint) |
| 173 | + |
| 174 | + return msg |
| 175 | + |
| 176 | + |
| 177 | +class InterfaceError(InterfaceMessage, Exception): |
163 | 178 | """An error caused by improper use of asyncpg API."""
|
164 | 179 |
|
| 180 | + def __init__(self, msg, *, detail=None, hint=None): |
| 181 | + InterfaceMessage.__init__(self, detail=detail, hint=hint) |
| 182 | + Exception.__init__(self, msg) |
| 183 | + |
| 184 | + |
| 185 | +class InterfaceWarning(InterfaceMessage, UserWarning): |
| 186 | + """A warning caused by an improper use of asyncpg API.""" |
| 187 | + |
| 188 | + def __init__(self, msg, *, detail=None, hint=None): |
| 189 | + InterfaceMessage.__init__(self, detail=detail, hint=hint) |
| 190 | + Warning.__init__(self, msg) |
| 191 | + |
165 | 192 |
|
166 | 193 | class PostgresLogMessage(PostgresMessage):
|
167 | 194 | """A base class for non-error server messages."""
|
|
0 commit comments