Handle 502 errors when inviting bad user to room
This commit is contained in:
parent
01d3b6b489
commit
877290fc00
|
@ -3,10 +3,10 @@
|
||||||
"""Custom exception definitions."""
|
"""Custom exception definitions."""
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import nio
|
import nio
|
||||||
|
|
||||||
|
|
||||||
# Matrix Errors
|
# Matrix Errors
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -14,7 +14,7 @@ class MatrixError(Exception):
|
||||||
"""An error returned by a Matrix server."""
|
"""An error returned by a Matrix server."""
|
||||||
|
|
||||||
http_code: int = 400
|
http_code: int = 400
|
||||||
m_code: str = "M_UNKNOWN"
|
m_code: Optional[str] = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_nio(cls, response: nio.ErrorResponse) -> "MatrixError":
|
def from_nio(cls, response: nio.ErrorResponse) -> "MatrixError":
|
||||||
|
@ -23,7 +23,7 @@ class MatrixError(Exception):
|
||||||
# Check for the M_CODE first: some errors for an API share the same
|
# Check for the M_CODE first: some errors for an API share the same
|
||||||
# http code, but have different M_CODEs (e.g. POST /login 403).
|
# http code, but have different M_CODEs (e.g. POST /login 403).
|
||||||
for subcls in cls.__subclasses__():
|
for subcls in cls.__subclasses__():
|
||||||
if subcls.m_code == response.status_code:
|
if subcls.m_code and subcls.m_code == response.status_code:
|
||||||
return subcls()
|
return subcls()
|
||||||
|
|
||||||
for subcls in cls.__subclasses__():
|
for subcls in cls.__subclasses__():
|
||||||
|
@ -69,6 +69,12 @@ class MatrixTooLarge(MatrixError):
|
||||||
m_code: str = "M_TOO_LARGE"
|
m_code: str = "M_TOO_LARGE"
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class MatrixBadGateway(MatrixError):
|
||||||
|
http_code: int = 502
|
||||||
|
m_code: str = ""
|
||||||
|
|
||||||
|
|
||||||
# Client errors
|
# Client errors
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|
|
@ -32,8 +32,8 @@ from nio.crypto import async_generator_from_data
|
||||||
|
|
||||||
from . import __app_name__, __display_name__, utils
|
from . import __app_name__, __display_name__, utils
|
||||||
from .errors import (
|
from .errors import (
|
||||||
BadMimeType, InvalidUserId, InvalidUserInContext, MatrixError,
|
BadMimeType, InvalidUserId, InvalidUserInContext, MatrixBadGateway,
|
||||||
MatrixNotFound, MatrixTooLarge, UneededThumbnail,
|
MatrixError, MatrixNotFound, MatrixTooLarge, UneededThumbnail,
|
||||||
UserFromOtherServerDisallowed,
|
UserFromOtherServerDisallowed,
|
||||||
)
|
)
|
||||||
from .html_markdown import HTML_PROCESSOR as HTML
|
from .html_markdown import HTML_PROCESSOR as HTML
|
||||||
|
@ -964,7 +964,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.get_profile(user_id)
|
await self.get_profile(user_id)
|
||||||
except MatrixNotFound as err:
|
except (MatrixNotFound, MatrixBadGateway) as err:
|
||||||
return err
|
return err
|
||||||
|
|
||||||
return await self.room_invite(room_id, user_id)
|
return await self.room_invite(room_id, user_id)
|
||||||
|
|
|
@ -108,6 +108,10 @@ BoxPopup {
|
||||||
qsTr("%1 not found, please verify the entered user ID")
|
qsTr("%1 not found, please verify the entered user ID")
|
||||||
.arg(user) :
|
.arg(user) :
|
||||||
|
|
||||||
|
type === "MatrixBadGateway" ?
|
||||||
|
qsTr("Server error while trying to find %1, please " +
|
||||||
|
"verify the entered user ID").arg(user) :
|
||||||
|
|
||||||
type === "MatrixUnsupportedRoomVersion" ?
|
type === "MatrixUnsupportedRoomVersion" ?
|
||||||
qsTr("%1's server does not support this room's version")
|
qsTr("%1's server does not support this room's version")
|
||||||
.arg(user) :
|
.arg(user) :
|
||||||
|
|
Loading…
Reference in New Issue
Block a user