Skip to content

Refactor Matrix API errors handling#85

Merged
PenguinBoi12 merged 2 commits into
mainfrom
fix/nio-error-response-handling
Jul 2, 2026
Merged

Refactor Matrix API errors handling#85
PenguinBoi12 merged 2 commits into
mainfrom
fix/nio-error-response-handling

Conversation

@PenguinBoi12

@PenguinBoi12 PenguinBoi12 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

matrix-nio's AsyncClient returns ErrorResponse instead of raising when an request error happens. Our current try/except pattern only caught lower level exception exceptions, so a rejected call either silently succeeded or raises a confusing AttributeError message instead of the real server error. To fix the issue and handle errors correctly, a wrapper called matrix_call() was added to wrap every AsyncClient calls and translates all type of error into a MatrixError with the actual API error message.

Additionally to adding the wrapper, all places making calls using the old pattern were refactored to use matrix_call instead.

Example

response = await matrix_call( 
    self.client.room_kick(
        room_id=self.room_id,
        user_id=user_id
    ), 
    error_message="Failed to kick user", 
)

@PenguinBoi12 PenguinBoi12 self-assigned this Jul 2, 2026
@PenguinBoi12 PenguinBoi12 requested a review from chrisdedman July 2, 2026 06:36
@PenguinBoi12 PenguinBoi12 changed the title Fix Matrix API errors handling Refactor Matrix API errors handling Jul 2, 2026

@chrisdedman chrisdedman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Great pattern for better errors handling. LGTM

@PenguinBoi12 PenguinBoi12 merged commit 91a8b53 into main Jul 2, 2026
4 checks passed
@PenguinBoi12 PenguinBoi12 deleted the fix/nio-error-response-handling branch July 2, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants