|
1 | | -# coding: utf-8 |
2 | | -from __future__ import unicode_literals |
| 1 | +from dataclasses import dataclass |
3 | 2 |
|
4 | 3 |
|
| 4 | +@dataclass |
5 | 5 | class HttpException(Exception): |
| 6 | + status: int |
| 7 | + message: str |
| 8 | + content: str |
6 | 9 |
|
7 | | - def __init__(self, status, message, content): |
8 | | - super(HttpException, self).__init__() |
9 | | - |
10 | | - self.status = status |
11 | | - self.message = message |
12 | | - self.content = content |
13 | | - |
14 | | - def __str__(self): |
15 | | - return repr(self) |
16 | | - |
17 | | - def __repr__(self): |
18 | | - return "HttpException(%s): %s%s" % ( |
19 | | - self.status, self.content, |
20 | | - "\n%s" % self.message if self.message else "") |
21 | | - |
| 10 | + def __str__(self) -> str: |
| 11 | + return f"HttpException({self.status}): {self.message}\n{self.content}" |
22 | 12 |
|
| 13 | +@dataclass |
23 | 14 | class ConnectionException(Exception): |
| 15 | + content: str |
24 | 16 |
|
25 | | - def __init__(self, content): |
26 | | - super(ConnectionException, self).__init__() |
27 | | - |
28 | | - self.content = content |
29 | | - |
30 | | - def __str__(self): |
31 | | - return repr(self) |
32 | | - |
33 | | - def __repr__(self): |
34 | | - return "ConnectionException: %s" % self.content |
| 17 | + def __str__(self) -> str: |
| 18 | + return f"ConnectionException: {self.content}" |
35 | 19 |
|
36 | 20 |
|
| 21 | +@dataclass |
37 | 22 | class JsonException(Exception): |
| 23 | + content: str |
38 | 24 |
|
39 | | - def __init__(self, content): |
40 | | - super(JsonException, self).__init__() |
41 | | - |
42 | | - self.content = content |
43 | | - |
44 | | - def __str__(self): |
45 | | - return repr(self) |
46 | | - |
47 | | - def __repr__(self): |
48 | | - return "JsonException: %s" % self.content |
| 25 | + def __str__(self) -> str: |
| 26 | + return f"JsonException: {self.content}" |
49 | 27 |
|
50 | 28 |
|
| 29 | +@dataclass |
51 | 30 | class ApiException(Exception): |
| 31 | + content: str |
52 | 32 |
|
53 | | - def __init__(self, content): |
54 | | - super(ApiException, self).__init__() |
55 | | - |
56 | | - self.content = content |
57 | | - |
58 | | - def __str__(self): |
59 | | - return repr(self) |
60 | | - |
61 | | - def __repr__(self): |
62 | | - return "ApiException: %s" % self.content |
| 33 | + def __str__(self) -> str: |
| 34 | + return f"ApiException: {self.content}" |
0 commit comments