@@ -46,19 +46,23 @@ def __init__(self, http_status: int, message: str = "") -> None:
46
46
47
47
MxSRE = Type [MatrixStandardRequestError ]
48
48
ec_map : Dict [str , MxSRE ] = {}
49
+ uec_map : Dict [str , MxSRE ] = {}
49
50
50
51
51
- def standard_error (code : str ) -> Callable [[MxSRE ], MxSRE ]:
52
+ def standard_error (code : str , unstable : Optional [ str ] = None ) -> Callable [[MxSRE ], MxSRE ]:
52
53
def decorator (cls : MxSRE ) -> MxSRE :
53
54
cls .errcode = code
54
55
ec_map [code ] = cls
56
+ if unstable :
57
+ cls .unstable_errcode = unstable
58
+ uec_map [unstable ] = cls
55
59
return cls
56
60
57
61
return decorator
58
62
59
63
60
64
def make_request_error (
61
- http_status : int , text : str , errcode : str , message : str
65
+ http_status : int , text : str , errcode : str , message : str , unstable_errcode : Optional [ str ] = None
62
66
) -> MatrixRequestError :
63
67
"""
64
68
Determine the correct exception class for the error code and create an instance of that class
@@ -70,14 +74,20 @@ def make_request_error(
70
74
errcode: The errcode field in the response JSON.
71
75
message: The error field in the response JSON.
72
76
"""
77
+ if unstable_errcode :
78
+ try :
79
+ ec_class = uec_map [unstable_errcode ]
80
+ return ec_class (http_status , message )
81
+ except KeyError :
82
+ pass
73
83
try :
74
84
ec_class = ec_map [errcode ]
75
85
return ec_class (http_status , message )
76
86
except KeyError :
77
87
return MatrixUnknownRequestError (http_status , text , errcode , message )
78
88
79
89
80
- # Standard error codes from https://matrix.org/docs/spec/client_server/r0.4.0.html #api-standards
90
+ # Standard error codes from https://spec. matrix.org/v1.3/client-server-api/ #api-standards
81
91
# Additionally some combining superclasses for some of the error codes
82
92
83
93
@@ -86,6 +96,21 @@ class MForbidden(MatrixStandardRequestError):
86
96
pass
87
97
88
98
99
+ @standard_error ("M_ALREADY_JOINED" , unstable = "ORG.MATRIX.MSC3848.ALREADY_JOINED" )
100
+ class MAlreadyJoined (MForbidden ):
101
+ pass
102
+
103
+
104
+ @standard_error ("M_NOT_JOINED" , unstable = "ORG.MATRIX.MSC3848.NOT_JOINED" )
105
+ class MNotJoined (MForbidden ):
106
+ pass
107
+
108
+
109
+ @standard_error ("M_INSUFFICIENT_POWER" , unstable = "ORG.MATRIX.MSC3848.INSUFFICIENT_POWER" )
110
+ class MInsufficientPower (MForbidden ):
111
+ pass
112
+
113
+
89
114
@standard_error ("M_USER_DEACTIVATED" )
90
115
class MUserDeactivated (MForbidden ):
91
116
pass
0 commit comments