33# This Source Code Form is subject to the terms of the Mozilla Public
44# License, v. 2.0. If a copy of the MPL was not distributed with this
55# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6- from typing import Callable , Dict , Optional , Type
6+ from __future__ import annotations
7+
8+ from typing import Callable , Type
79
810from .base import MatrixError
911
@@ -12,25 +14,30 @@ class MatrixRequestError(MatrixError):
1214 """An error that was returned by the homeserver."""
1315
1416 http_status : int
15- message : Optional [ str ]
17+ message : str | None
1618 errcode : str
1719
1820
1921class MatrixUnknownRequestError (MatrixRequestError ):
2022 """An unknown error type returned by the homeserver."""
2123
24+ http_status : int
25+ text : str
26+ errcode : str | None
27+ message : str | None
28+
2229 def __init__ (
2330 self ,
2431 http_status : int = 0 ,
2532 text : str = "" ,
26- errcode : Optional [ str ] = None ,
27- message : Optional [ str ] = None ,
33+ errcode : str | None = None ,
34+ message : str | None = None ,
2835 ) -> None :
2936 super ().__init__ (f"{ http_status } : { text } " )
30- self .http_status : int = http_status
31- self .text : str = text
32- self .errcode : Optional [ str ] = errcode
33- self .message : Optional [ str ] = message
37+ self .http_status = http_status
38+ self .text = text
39+ self .errcode = errcode
40+ self .message = message
3441
3542
3643class MatrixStandardRequestError (MatrixRequestError ):
@@ -45,11 +52,11 @@ def __init__(self, http_status: int, message: str = "") -> None:
4552
4653
4754MxSRE = Type [MatrixStandardRequestError ]
48- ec_map : Dict [str , MxSRE ] = {}
49- uec_map : Dict [str , MxSRE ] = {}
55+ ec_map : dict [str , MxSRE ] = {}
56+ uec_map : dict [str , MxSRE ] = {}
5057
5158
52- def standard_error (code : str , unstable : Optional [ str ] = None ) -> Callable [[MxSRE ], MxSRE ]:
59+ def standard_error (code : str , unstable : str | None = None ) -> Callable [[MxSRE ], MxSRE ]:
5360 def decorator (cls : MxSRE ) -> MxSRE :
5461 cls .errcode = code
5562 ec_map [code ] = cls
@@ -62,7 +69,11 @@ def decorator(cls: MxSRE) -> MxSRE:
6269
6370
6471def make_request_error (
65- http_status : int , text : str , errcode : str , message : str , unstable_errcode : Optional [str ] = None
72+ http_status : int ,
73+ text : str ,
74+ errcode : str | None ,
75+ message : str | None ,
76+ unstable_errcode : str | None = None ,
6677) -> MatrixRequestError :
6778 """
6879 Determine the correct exception class for the error code and create an instance of that class
@@ -73,6 +84,7 @@ def make_request_error(
7384 text: The raw response text.
7485 errcode: The errcode field in the response JSON.
7586 message: The error field in the response JSON.
87+ unstable_errcode: The MSC3848 error code field in the response JSON.
7688 """
7789 if unstable_errcode :
7890 try :
0 commit comments